开发者

C++ Win32 API Delete file with progress bar

Using the windows api, is there开发者_如何学C any way to delete a large file (lets say 1gb+), and monitor the progress somehow? I'm sure its possible but I have no idea where to start..

EDIT: Should have been more specific, I want to move the file to the recycle bin, and show a progress bar similar to explores, though I might want the progress bar in a console or something so I don't want an exact replica.

EDIT 2: Yeaah guess it is instant, should have tested before I asked the question. Anyway to just close this question?


Use SHFileOperation with the FO_DELETE func and FOF_ALLOWUNDO flag to move a file to the Recycle Bin. Progress will automatically be shown unless you also specify FOF_SILENT.

SHFILEOPSTRUCT fileop = { 0 };
fileop.hwnd = hwndMain; /* your window */
fileop.wFunc = FO_DELETE;
fileop.pFrom = szFilePathToDelete;
fileop.fFlags = FOF_ALLOWUNDO /* | FOF_NOCONFIRMATION to recycle without prompting */;
int error = SHFileOperation(&fileop);

Update: As noted in the question edit, progress won't be shown for a single file, but it will be shown if recycling an entire directory. This also doesn't let you override the UI (e.g., to display progress in a console window).


Perhaps you could progressively truncate it using SetEndOfFile? http://msdn.microsoft.com/en-us/library/aa365531(v=vs.85).aspx. Then removing the inode (or whatever it's called in Windows-land) could be quickly done.

[update]Just tested; the other guys are right. Removing the inode (delete) is instantaneous on a 1gb file.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜