Zeller
Mitglied
Hier noch meinen endgültigen Code zum auslese der files aus einem
Ordner und dessen Unterordnern inkl. filecounter.
Ordner und dessen Unterordnern inkl. filecounter.
![Smile :-) :-)](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f642.png)
Code:
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <windows.h>
using namespace std;
void filesearch(char *path);
int counter=0;
int main(int argc, char *argv[])
{
char path[MAX_PATH]="e:/fotos";//Pfad eingeben
filesearch(path);
cout<<counter<<" files\n";
return 0;
}
void filesearch(char *path)
{
strcat(path, "\\");
char path1[MAX_PATH];
strcpy(path1,path);
strcat(path1, "*");
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind=FindFirstFile(path1, &FindFileData);
do
{
counter++;
if(!(strcmp(FindFileData.cFileName,".")== 0 ||
strcmp(FindFileData.cFileName,"..")==0 ))
{
printf("%s",FindFileData.cFileName);
if( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
{
printf("\t<DIR>\n\n");
char *temp=FindFileData.cFileName;
char sich[MAX_PATH];
strcpy(sich,path);
strcat(path, temp);
filesearch(path);
strcpy(path,sich);
}
if( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN )
printf("\t<Hidden>");
if( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED )
printf("\t<Compressed>");
if( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM )
printf("\t<System>");
if( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_ENCRYPTED )
printf("\t<Encrypted>\n");
printf("\n");
}
}
while ( FindNextFile(hFind, &FindFileData) );
FindClose(hFind);
}