Ordner durchsuchen

Hallo Kalsan!

Ich bin nun C++ -Mensch, habe mich aber bemüht, das möglichst C-gemaess zu schreiben. Die zwei Strings, dir man als erstes von Win32 kriegt, sind „.“ und „…“ (aus historischen Gruenden).
Siehe den Code weiter unten.

lG
Martin B

#include 
#include 

char\* dirList(char \*path, int \*isDir, DWORD \*size)
{
 static WIN32\_FIND\_DATAA wfd;
 static HANDLE hFind;
 size = 0;
 /\* if (!isDir || !size) {return "error: pointers have no memory...\n";}
 \*/

 if (path)
 {
 ZeroMemory(&wfd, sizeof(WIN32\_FIND\_DATAA));
 hFind = INVALID\_HANDLE\_VALUE;
 hFind = FindFirstFile(path, &wfd);
 if (hFind == INVALID\_HANDLE\_VALUE)
 {FindClose(hFind); return 0;}
 }
 else {
 if (! FindNextFile(hFind, &wfd))
 {FindClose(hFind); return NULL;}
 }

 if (wfd.dwFileAttributes & FILE\_ATTRIBUTE\_DIRECTORY)
 { \*isDir = 1; 
 /\* \*size = 0; \*/
 }
 else
 { \*isDir = 0; 
 /\* \*size = wfd.nFileSizeLow; \*/
 }

 return wfd.cFileName;
}

int main()
{
 /\* "C:/winnt/\*.\*"; = Ordner und Dateien kriegen 
 (\*.\* in beliebiger Kombination) \*/
 char \*findWhere = "C:/winnt/\*.ini"; 
 DWORD gr = 0;
 int isDir = 0;

 printf ("press any key to read:\n");
 /\* beim ersten Mal Pfad uebergeben... \*/
 char \*got = dirList(findWhere, &isDir, &gr);
 do
 {
 if ((\*got == '.') || (\*got == '?')) {continue;}
 printf ("%c %s\n", (isDir ? 'D' : ' '), got);
 } 
 /\*...dann NULL \*/
 while (got = dirList(NULL, &isDir, &gr));

 system("pause");
 return 0;
}