简体   繁体   中英

How can I delete files from folders and subfolders before deleting the subfolders themselves in Win32?

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 FindFirstFile() / FindNextFile() ) - if a file is encountered, delete it, otherwise recurse into the folder and then delete the folder when the recursion returns.

Or you can just use IFileOperation and the system will do all the work for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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