C# - Deleting a file permanently

后端 未结 2 1147
情深已故
情深已故 2020-12-10 19:49

I\'ve been out of the C# game for a while since I started iPhone stuff, but how can you delete a file completely (so its not stored in memory) and isn\'t recoverable. If you

相关标签:
2条回答
  • 2020-12-10 20:10

    It's certainly possible to overwrite a file so that the previous content cannot be recovered. But this has to be done by the drive itself to make sure the correct block is overwritten... C# interacts with the filesystem, not physical blocks, so won't provide any security.

    The actual way to ask a drive to securely erase something varies with interface (ATAPI vs SATA, vs USB mass-storage vs SCSI vs firewire), and C# doesn't provide a simple way of commanding at this level.

    0 讨论(0)
  • 2020-12-10 20:22

    sdelete run this command via Process in c#.

    Process p = new Process();
    p.StartInfo = new ProcessStartInfo( "cmd", "/c sdelete -p 1 -s -z -q -a 'path/to/director' )
        {
            RedirectStandardOutput = true,
            UseShellExecute = false,
            CreateNoWindow = true
        };
    p.Start();
    string output = p.StandardOutput.ReadToEnd();
    p.WaitForExit();
    

    sdelete can be downloaded here

    0 讨论(0)
提交回复
热议问题