I need some help on how to delete all contents of a folder. I wanted to make a simple program that deletes everything in my startup folder but not the folder itself.
Printable View
I need some help on how to delete all contents of a folder. I wanted to make a simple program that deletes everything in my startup folder but not the folder itself.
What OS are you on?
What part are you having trouble with?
Post the code you have so far.
You can use the system() command in stdlib.h. It's use is normally discouraged because it isn;t portable, but if you're just making a program for personal use, simpler is better, I think. You pass system() a string, and the string is excuted as a shell command. So in windows, you can just do
or on a UNIX system you could useCode:system("cd c:\startup"); // Or wherever it is
system("del *.*");
instead of 'del'. There is no method in standard c that will do this programmatically - you'll either need to get a system-specific API, or use shell commands like I do above.Code:system("rm *.*");
Run strace on the rm command and see that happens. This will give a clue on how the system actually removes a file....ie unlink.
Perhaps you can also look at this FAQ which gives much information on how to handle files and directories both on Windows and Unix platform.
ssharish
There we go i got it now :D