简体   繁体   English

RemoveDirectory()如果​​目录不为空?

[英]RemoveDirectory() if the directory is not empty?

On the page ( RemoveDirectory() - function ) they say : " The path of the directory to be removed. This path must specify an empty directory , and the calling process must have delete access to the directory. " 在页面上( RemoveDirectory() - 函数 ),他们说:“ 要删除的目录的路径。此路径必须指定一个空目录 ,并且调用进程必须具有对该目录的删除访问权限。

My question is : How do I delete an non-empty directory using this function ? 我的问题是:如何使用此功能删除非空目录? Is that posible ? 那可能吗? Any help will be apreciate ! 任何帮助将是一个很好的帮助!

The short answer is that you don't. 简短的回答是你没有。

If you need to remove a non-empty directory, you do a depth-first traversal of the directory structure. 如果需要删除非空目录,则执行目录结构的深度优先遍历。 As you traverse an individual directory, you erase all the files it contains. 在遍历单个目录时,将擦除它包含的所有文件。 If it contains any sub-directories, you traverse into them, deleting their contents then deleting the (now empty) directory. 如果它包含任何子目录,您将遍历它们,删除它们的内容,然后删除(现在为空)目录。 Lather, rinse, repeat. 泡沫,冲洗,重复。

Alternatively, use SHFileOperation or (if you're feeling truly masochistic) IFileOperation , to handle the heavy lifting for you (but beware that the latter is a COM interface, so getting it to handle the heavy lifting will be at least twice as much work as doing the job yourself). 或者,使用SHFileOperation或(如果你感觉真的受虐待) IFileOperation ,为你处理繁重的工作(但要注意后者是一个COM接口,所以让它来处理繁重的工作将至少是工作量的两倍自己做的工作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM