I'm having a problem removing a directory after it's subfolders / files have been removed. I'm using FindFirstFile, FindNextFile, RemoveDirectory, etc. For instance I have this directory:
As you can see it deletes all files in searchfile-e3798fd4 and removes the directory, but leaves the parent directory 'ipch', which i want deleted as well. This is my full current code:
I'm aware that the problem exists where I actually RemoveDirectory( sPath ); Because that function is called it sees that ipch isn't empty, therefore doesn't delete it. then recursives and continues on.
解決
You have three problems with your recursion, making it not match the algorithm Tim describes:
You are trying to delete the directory before the contents. But RemoveDirectory only deletes empty directories.
You (attempt to) delete subdirectories, but leave files in place. This also will prevent removal of the directory.
You never delete the original directory.
Moving the RemoveDirectory call from inside the loop to the end of the function will solve these problems.
他のヒント
I didn't look at all of your code, but I would imagine that, just like @BenVoigt and @TimBergel said, you need something like this: