C++ Win32 API 删除带进度条的文件 [英] C++ Win32 API Delete file with progress bar
问题描述
使用windows api,有没有办法删除一个大文件(比如1gb+),并以某种方式监控进度?我确定这是可能的,但我不知道从哪里开始..
Using the windows api, is there 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..
应该更具体,我想将文件移动到回收站,并显示一个类似于探索的进度条,尽管我可能想要控制台或其他东西中的进度条,所以我不想要精确的复制品.
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.
编辑 2:是的,我猜它是即时的,应该在我问这个问题之前测试过.无论如何要结束这个问题?
EDIT 2: Yeaah guess it is instant, should have tested before I asked the question. Anyway to just close this question?
推荐答案
使用 SHFileOperation 使用 FO_DELETE
func 和 FOF_ALLOWUNDO
标志将文件移动到回收站.除非您还指定 FOF_SILENT,否则将自动显示进度.
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);
更新:如问题编辑中所述,不会显示单个文件的进度,但如果回收整个目录,则会显示进度.这也不允许您覆盖 UI(例如,在控制台窗口中显示进度).
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).
这篇关于C++ Win32 API 删除带进度条的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!