16. juli 2001 - 00:33
Der er
3 kommentarer og
1 løsning
filefind kommando
Findes der en funktion, hvori man kan lede hele sin hd ignennem efter et specielt filnavn?
Altså, ligesom den der findes i:
Start -> Søg Efter -> Filer eller Mapper
Hvis der ikke er funktion til dette i forvejen, hvordan ville man så kode dette ??
Et kørende eksempel ville være rart ;-)
Her er et uddrag fra en gammel funktion jeg lavede til at lede vores filservere igemmen for mp3\'ere (heh).
int Recurse(const char *sname, const char *ext)
{
HANDLE handle;
WIN32_FIND_DATA win32_find_data;
char path[255];
strcpy(path, sname);
strcat(path, \"\\\\*\");
handle = FindFirstFile(path, &win32_find_data);
if (handle == INVALID_HANDLE_VALUE)
return -1;
do {
if ((win32_find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
(win32_find_data.cFileName[0] != \'.\'))) {
strcpy(path, sname);
strcat(path, \"\\\\\");
strcat(path, win32_find_data.cFileName);
//std::cout << path << std::endl;
if (Recurse(path, ext) < 0) {
return -1;
}
} else {
if (win32_find_data.cFileName[0] != \'.\') {
strcpy(path, sname);
strcat(path, \"\\\\\");
strcat(path, win32_find_data.cFileName);
char *FileNameExt = (char *)win32_find_data.cFileName+(strlen(win32_find_data.cFileName)-4);
if (strcmp(FileNameExt, ext) == 0)
std::cout << path << std::endl;
if (Recurse(path, ext) == 0)
return -1;
}
}
} while (FindNextFile(handle,&win32_find_data));
if (!FindClose(handle))
return -1;
return 0;
}