Source code :
#include <stdio.h>
#include <dirent.h>
void main(void){
//choose the folder path
char DIRPATH[]="c:\\images\\";
DIR *dir;
struct dirent *entry;
dir=opendir ( DIRPATH );
//checking the folder content
while ( NULL != ( entry = readdir ( dir ) ) ) {
DIR *test;
char filePath[260];
sprintf ( filePath,"%s%s", DIRPATH, entry->d_name );
errno=0;
test=opendir ( filePath );
if (test==NULL && errno!=0){
printf("%s\n",entry->d_name);
// ... (your source code)
// ...
//...
} else {
closedir(test);
}
}
closedir(dir);
}
Attention!! (Penting)
Ketika compiler gagal meng-compile kode dan keluar pemberitahuan error seperti berikut :
‘dirent.h’: No such file or directory
berarti dalam folder ‘include’ tidak terdapat header file bernama “dirent.h”
Please download the file from = http://www.softagalleria.net/download/dirent/
download file, unzip the package and copy the “dirent.h” to C:\Program Files\Microsoft Visual Studio 9.0\VC\include
Target file path bisa berbeda tergantung versi dari Visual Studio yang digunakan.
(Saya menggunakan Visual Studio 2008)
Selamat mencoba!