So you're talking about recursive function call. This is very handy in a case like deleting subfolders and contents. Here's my code that finds all .mp3 files and changes their attributes. I think there's some bug in it but you get the picture.
void searchloop(void) {
long res;
struct _finddata_t fileinfo;
res = _findfirst("*.*", &fileinfo);
while(1) {
if((strcmp(fileinfo.name, ".") != 0)&&(strcmp(fileinfo.name, "..") != 0))
if(_chdir(fileinfo.name) == 0) {
searchloop();
} else {
if(!strcmp(fileinfo.name, ".mp3")) {
SetFileAttributes(fileinfo.name, FILE_ATTRIBUTE_NORMAL);
}
}
if(_findnext(res, &fileinfo) < 0)
break;
}
_chdir("..");
}
: I am taking a day or two off from my world editor to build a simple (actually, rebuild) temporary file remover, which will delete all the files in "Windows\TEMP" and in any of it's subfolders, as well as the actual subfolder. I have two questions about this though. When FindFirstFile or FindNextFile return, they only return the file or directory name, and I need the full drive and path to delete files and subfolders. Second, can a function call on itself? The way I plan on doing it is this (this is my actual code so far):
:
: void remove(char place[512])
: {
: WIN32_FIND_DATA fd;
:
: fn = FindFirstFile(place, &fd);
:
: if(fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
: {
: /*
: First get the full path and directory name
: Now call remove() with that info
: Once it returns, you can delete the empty folder!
: */
: }
: else
: //Just delete the file, if not a dir
:
: //Code in a loop with FindNextFile here!
: return;
: }
:
: void clean(HWND cwnd)
: {
: if(strstr(paths[0], "Not used.") == NULL)
: remove(paths[0]);
: return;
: }
:
: Can somebody please help me out with this? I appreciate it.
: -
Sephiroth
: