Hvis du kører alm. C++ under DOS hedder de tilsvarende funktioner findfirst, og findnext og modtager/returnerer en struktur der hedder ffb. Alle funktioner, samt strukturen er defineret i <dir.h>
void main(int argc,char* argv[]){ delbefore=time(0)-1209599;// 14 days - 1 sec searchdir(\"E:\\\\FileSysDel\\\\Release\\\\test\");//must call with full path or recursion will fail printf(\"\\n%i files deleted\\n\",results); }
int searchdir(char *dir){ if(!dir){ printf(\"\\nError: !dir\\n\"); return -1; } if(_chdir(dir)){ printf(\"\\nError: _chdir(\\\"%s\\\") failed\\n\",dir); return -1; } _finddata_t file; long hnd, res=0; if((hnd=_findfirst(\"*\",&file))!=-1){ while(!res){ if(file.name[0]==\'.\'&&(file.name[1]==\'\\0\'||(file.name[1]==\'.\'&&file.name[2]==\'\\0\'))){ res=_findnext(hnd,&file); continue; } if(file.attrib & _A_SUBDIR){ char newdir[500]; newdir[0]=\'\\0\'; if(dir){ strcpy(newdir,dir); strcat(newdir,\"\\\\\"); } strcat(newdir,file.name); searchdir(newdir); res=_findnext(hnd,&file); continue; } if(file.time_access<delbefore&&file.time_create<delbefore&&file.time_write<delbefore){ _chdir(dir);//recursive calls will change cwd if(!_unlink(file.name)){ results++; printf(\"%s\\\\%s deleted\\n\",dir,file.name); }else{ printf(\"%s\\\\%s could not be deleted\\n\",dir,file.name);
} }else{ printf(\"%s\\\\%s is to recent\\n\",dir,file.name); }
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.