The C language implements traversing all files in a folder
- 2020-05-12 02:59:33
- OfStack
The C language implements traversing all files in a single folder
Recently, I have learned the basic knowledge of C language. There is one requirement that I need to traverse the files in the folder, which is very good for this kind of implementation. Then I made a code to traverse all the files and made the following records:
Implementation code:
#include <stdio.h>
#include <io.h>
int main (void)
{
_finddata_t fileDir;
long lfDir;
if((lfDir = _findfirst(dir,&fileDir))==-1l)
printf("No file is found\n");
else{
printf("file list:\n");
do{
printf("%s\n",fileDir.name);
}while( _findnext( lfDir, &fileDir ) == 0 );
}
_findclose(lfDir);
return 0;
}
Thank you for reading, I hope to help you, thank you for your support of this site!