1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| #include "fichier.h"
//receive: 1) the name of the directory
// 2) The root name of the picture
//for example argv[0] is "C:\Src\"
// argv[1] id "frame"
// the function browses into C:\Src\ and return all the files whose name is beggining by "frame"
void fichiers (int argc, char **argv)
{
if(argc == 2)
{
//reading argument
char temp_dir[100];
char temp_file[100];
strcpy(temp_dir, argv[0]);
strcpy(temp_file, argv[1]);
short file_len = strlen(argv[1]);
short dir_len = strlen(argv[0]);
short Aslash_nb = 0;
// ASCII '\' => 47
for(short i=0;i<dir_len;i++)
if(temp_dir[i] == 47)
Aslash_nb++;
char *folder = new char[dir_len+Aslash_nb];// = "C:\\Src\\*";
char *folder2 = new char[dir_len+Aslash_nb+1];// = "C:\\Src\\";
short j = 0;
for(i=0;i<dir_len;i++)
{
if(temp_dir[i] == 47)
{
folder[j] = temp_dir[i];
folder2[j++] = temp_dir[i];
folder[j] = 47;
folder2[j++] = 47;
}
else
{
folder[j] = temp_dir[i];
folder2[j++] = temp_dir[i];
}
}
sprintf(folder2, "%c", "*");
char root[] = "..";
HANDLE hFile = NULL;
HANDLE *qq;
WIN32_FIND_DATA ffInfo = {0};
hFile = FindFirstFile(folder, &ffInfo);
if(hFile == INVALID_HANDLE_VALUE)
{
exit(1);
}
short re;
char current_folder[260];
do
{
// Traitement
re = FindNextFile(hFile, &ffInfo);
if(strcmp(current_folder,ffInfo.cFileName) != 0)
{
if(ffInfo.dwFileAttributes == 16)
{
// folder found
char nom[260];
strcpy(nom, ffInfo.cFileName);
if(*nom != *root)
{
char chemin[260];
sprintf(chemin, "%s%s%s", folder2, nom, "\\*");
printf("%s\n", chemin);
// close handle
FindClose(hFile);
// store the folder adress
HANDLE *qq = new HANDLE[1];
//enter in the folder
qq[0] = FindFirstFile(chemin, &ffInfo);
do{
re = FindNextFile(qq[0], &ffInfo);
if(ffInfo.dwFileAttributes == 32)
{
if(file_len == strspn(temp_file, ffInfo.cFileName))
{
//ici on envoit le nom des fichiers
//
printf("%s\n", ffInfo.cFileName);
}
}
}while(re);
re = true;
//end of the folder
FindClose(qq[0]);
HANDLE hFile = NULL;
hFile = FindFirstFile(folder, &ffInfo);
delete[]qq;
do{
re = FindNextFile(hFile, &ffInfo);
if(ffInfo.dwFileAttributes == 16)
strcpy(current_folder, ffInfo.cFileName);
}while((strcmp(current_folder,nom) != 0) && (re == 1));
}
}
}
else
re = 0;
} while(re);
FindClose(hFile);
}
else
{
printf("Not enought argument in function File\n");
}
} |
Partager