开发者

Delete all files from pendrive using C program

I am searching for a solution to delete all files from my pendrive using a C program. I don't want the code to detect the pendrive as that's not a concern right now. I would appreciate any links that could help me out on this.

Note: I am working on Windows 7 64-bit and开发者_Python百科 I want to delete the entire contents from my pendrive, which contains .exes and .dlls.

Thanks and Regards, Radix


The non-hack correct way to do this, is via the Virtual Disk Service.


If you can't use something like rm -rf F:\* and you really do need to implement it yourself in C then I think I'd probably opt for a recursive solution based on FindFirstFile and FindNextFile. These are the native Windows APIs for enumerating directories. Not remotely portable, but it doesn't seem that's a requirement.

Basically the idea is that you write a function, EmptyDir(), say, whose job it is to delete the contents of a directory. The function uses FindFirstFile and FindNextFile to walk the contents of the directory. When a file is encountered it is deleted. When a directory is encountered, EmptyDir() is called recursively. The last job of EmptyDir(), before it returns, is to delete the now empty directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜