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.
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.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
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
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein
There we go i got it now