C# 类来取消删除文件?
我正在开发一个旨在恢复已删除文件的应用程序从系统(包括来自回收站的和那些已经从回收站清空但仍然可以理解的)和格式化驱动器。我决定使用 C# 作为语言,但我很难找到处理这个问题的类。有谁知道用于查找已删除文件、检索它们的任何类/方法或有关此事的任何教程或帮助。我在这个问题上经验很少,所以我们将非常感谢任何帮助。
Possible Duplicate:
How do I restore a file from the recycle bin using C#?
Recovering deleted file on windows
I am working on an application that is intended to recover deleted files from the system(both those from recycle Bin and those already emptied from the recycle bin but still understandable) and formatted drives. I decided on c# as language, but I have trouble finding classes that deal with this problem. Does anyone know any classes/methods for finding deleted files, retrieving them or any tutorials or helps on the matter. I have little experience on the subject so any help would be strongly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有内置类可以执行您要求的操作。
实际上,恢复删除文件是一个困难的过程,它需要对文件系统有非常低的了解。因此,要做的第一件事是获取有关包含要取消删除的文件的驱动器的信息。基本上你首先想了解它的文件系统。
您必须经常使用 P/Invoke。首先获取目标驱动器的句柄:
一旦获得文件系统的名称,您就必须手动从驱动器读取原始数据。 您将读取的内容完全取决于驱动器的文件系统。不管怎样,你必须获得相关硬盘的句柄:
现在你必须了解很多关于你的文件系统的部分......
对于NTFS文件系统,您必须了解主文件表的概念。事实上,这很难。
对于 FAT 文件系统,这不太复杂,但您仍然需要研究 FS 一段时间。从维基百科开始。
从使用
CreateFile
获得的句柄中,您现在将逐字节(实际上逐个扇区)读取(原始访问)到磁盘中,以使用ReadFile
获取所需的信息>。对于NTFS,首先要获取MFT的起始扇区......然后你必须“解析”MFT并查找已删除的文件......
我不会在这里解释整个过程。有关示例,请参阅此链接。
祝你好运:)
现在您可能想使用已经完成所有这些工作的第三方应用程序,并从您自己的程序中使用它(如评论中所述的命令行工具)。
There are no built-in classes to do what you asked.
Actually, undeleting files is a hard process and it requires a very low level knowledge of your file system. So the first thing to do is to get information about the drive that contains the file you want to undelete. Basically you first want to know its file system.
You'll have to use P/Invoke a lot. Firstly get a handle to the drive you target:
Once you have the name of the file system, you'll have to manually read raw data from the drive. What you'll read entirely depends on the file system of the drive. Anyway, you'll have to get a handle to the associated hard disk for that:
Now it's the part you'll have to know a lot about your file system...
For NTFS file system, you'll have to understand the concept of Master File Table. Actually, that's pretty hard.
For FAT file systems, that's less complicated but still, you'll have to study the FS for a while. Start with wikipedia.
From the handle you got using
CreateFile
, you'll now read (raw access) byte per byte (sector by sector actually) into the disk to get the information you want usingReadFile
.For NTFS, first thing it to get the starting sector of the MFT.... then you'll have to "parse" the MFT and look for deleted files...
I won't explain the whole process here. See this link for an example.
So good luck with that :)
Now you probably might want to use a third party application that already does all this stuff and use it from your own program (command line tool as said in the comments).