marcuswork
Programmer
Hey all, I have a C++ program that is manipulating files in a Unix (sun) directory. Let's say I have a main_dir and then inside of main_dir are a bunch of files and a temp_dir. I want to delete all the files "except" for the temp_dir. Is there a single command I could use to remove "all" files?
I've tried doing:
remove("main_dir/*); // note these are strings converted
// into char* pointers in reality
remove("main_dir/*.*"
; // by calling my_string.c_str()
system("rm *"
;
None of these work. Calling the "system" command gives an error that it can't delete a certain file (usually the first one it tries to delete). Also, I've tried to use scandir() but get an error that it can't find the include file <sys/dir.h>. Any help on this would be greatly appreciated.
Also, after removing all files from main_dir, I'd like to "move" all the files from the nested temp_dir back into the main_dir. How would I accomplish this in C++ on a Sun machine?
Thanks,
Marcus
I've tried doing:
remove("main_dir/*); // note these are strings converted
// into char* pointers in reality
remove("main_dir/*.*"
system("rm *"
None of these work. Calling the "system" command gives an error that it can't delete a certain file (usually the first one it tries to delete). Also, I've tried to use scandir() but get an error that it can't find the include file <sys/dir.h>. Any help on this would be greatly appreciated.
Also, after removing all files from main_dir, I'd like to "move" all the files from the nested temp_dir back into the main_dir. How would I accomplish this in C++ on a Sun machine?
Thanks,
Marcus