在Win32中删除子文件夹之前,如何从文件夹和子文件夹中删除文件? [英] How can I delete files from folders and subfolders before deleting the subfolders themselves in Win32?
问题描述
删除Win32 API(RemoveDirectory)中的目录要求删除该文件夹下的所有文件,然后再删除文件夹。因此,假设我在根目录下有一个文件夹foo,其中有文件,还有一些子文件夹,也可能有或没有文件,如何递归删除所有文件,然后是子文件夹?
它通常需要一个递归函数,读取要删除的目录的内容(通过 或者您可以使用 Deleting a directory in Win32 API (RemoveDirectory) requires all files under that folder to be deleted before deleting the folder. So assuming I have a folder 'foo' at the root, with files in it, along with some subfolders that also may or may not have files, how do I recursively delete all the files, and then the subfolders? It generally requires a recursive function, that reads the contents of the directory you want to delete (via Or you can just use 这篇关于在Win32中删除子文件夹之前,如何从文件夹和子文件夹中删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! FindFirstFile / code> /
FindNextFile()
) - 如果遇到文件,请将其删除,否则递归到文件夹,然后在递归返回时删除文件夹。 / p>
IFileOperation
,系统将为您完成所有工作。FindFirstFile()
/FindNextFile()
) - if a file is encountered, delete it, otherwise recurse into the folder and then delete the folder when the recursion returns.IFileOperation
and the system will do all the work for you.