Does anybody know how to delete an entire folder and its contents including other folders? I'm using MSVC++ 6.0 and the program is in win32.
Thanks
-Chris
Does anybody know how to delete an entire folder and its contents including other folders? I'm using MSVC++ 6.0 and the program is in win32.
Thanks
-Chris
i think there's a rmdir command in dir.h
but i'm not sure wether it can delete the dir including its contents.
use the FindFirstFile/FindNextFile combination to delete every file int the directory, one by one, then delete the directory
I know how to use the FindFirstFile/FindNextFile combination but how do I "...then delete the directory"?use the FindFirstFile/FindNextFile combination to delete every file int the directory, one by one, then delete the directory
There's a Win32 function - RemoveDirectory().
Here is the sample out of the MSDN files.... this is in the help files....
Code:/* MAKEDIR.C */ #include <direct.h> #include <stdlib.h> #include <stdio.h> void main( void ) { if( _mkdir( "\\testtmp" ) == 0 ) { printf( "Directory '\\testtmp' was successfully created\n" ); system( "dir \\testtmp" ); if( _rmdir( "\\testtmp" ) == 0 ) printf( "Directory '\\testtmp' was successfully removed\n" ); else printf( "Problem removing directory '\\testtmp'\n" ); } else printf( "Problem creating directory '\\testtmp'\n" ); } Output Directory '\testtmp' was successfully created Volume in drive C is CDRIVE Volume Serial Number is 0E17-1702 Directory of C:\testtmp 05/03/94 12:30p <DIR> . 05/03/94 12:30p <DIR> .. 2 File(s) 0 bytes 17,358,848 bytes free Directory '\testtmp' was successfully removed
zMan
For the person who suggested RemoveDirectory():
RemoveDirectory() only removes a directory if it is completely empty. Is there any similar function that can erase the data and other folders within a folder?
For last person who posted here:
Your example is a console app and uses system commands etc, and what i am doing is in windows. Is there a way to do this with windows?
Thanks
-Chris
Hence the FindFirstFile/FindFirstFile to remove the contents.RemoveDirectory() only removes a directory if it is [snippity snip]
Oh thanks. But what if there are other folders within this directory? Is there any way to get rid of these?
use recursion
wouldn't the simple remove() function do the job if you simply deleted the directory, or would it leave the other files there?
Don't know if it exist in the newer versions of windows. But DELTREE was a dos command to delete a directory and everything inside (including other directories).