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
|
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
void recherche(int choix2, char* path, char* slash, HANDLE hSearch, WIN32_FIND_DATA File, LARGE_INTEGER filesize) {
if (path == NULL) {
hSearch = FindFirstFile(slash, &File);
}else{
hSearch = FindFirstFile(strcat(path,slash), &File);
}
if (hSearch != INVALID_HANDLE_VALUE) {
printf("Liste des fichiers: \n\n");
do {
if (File.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // Si c'est un dossier
printf("%s <DIR>\n", File.cFileName);
if (choix2 == 3) {
recherche(choix2, strcat(path,File.cFileName), slash, hSearch, File, filesize);
}
}else{
filesize.LowPart = File.nFileSizeLow;
filesize.HighPart = File.nFileSizeHigh;
printf("%s %ld bytes\n", File.cFileName, filesize.QuadPart);
}
} while (FindNextFile(hSearch, &File));
FindClose(hSearch);
}else{
printf("Erreur");
}
}
int main(int argc, char *argv[]) {
WIN32_FIND_DATA File;
LARGE_INTEGER filesize;
HANDLE hSearch;
int choix1 = 0, choix2 = 0;
char* path = NULL;
char* nom = NULL;
char slash[20] = "/";
printf("\n\nQue voulez-vous faire?\n\n1 - Effectuer une recherche de fichier\n2 - Stocker un fichier dans mon catalogue\n3 - Quitter\n\n");
scanf("%ld", &choix1);
if (choix1 == 1) {
nom = (char *)malloc (20*sizeof(char));
printf("Entrez le nom du fichier que vous voulez chercher :\n\n");
scanf("%s", nom);
strcat(slash,nom);
printf("\n1 - Effectuer une recherche dans le dossier courant\n2 - Effectuer une recherche dans la corbeille\n3 - Effectuer une recherche sur tout l'ordinateur\n4 - Effectuer une recherche personnalisée\n\n");
scanf("%ld", &choix2);
switch(choix2) {
case 1:
printf("Recherche dans le dossier courant en cours...\n\n");
recherche(choix2, path, nom, hSearch, File, filesize);
break;
case 2:
printf("Recherche dans la corbeille en cours...\n\n");
//slash = (char *)malloc (22*sizeof(char));
break;
case 3:
path = (char *)malloc (50*sizeof(char));
printf("Veuillez taper le chemin complet du dossier de départ :\n\n");
scanf("%s", path);
printf("Recherche sur tout l'ordinateur en cours...\n\n");
recherche(choix2, path, slash, hSearch, File, filesize);
break;
case 4:
path = (char *)malloc (50*sizeof(char));
printf("Veuillez taper le chemin complet du dossier à scanner :\n\n");
scanf("%s", path);
recherche(choix2, path, slash, hSearch, File, filesize);
break;
}
}else if (choix1 == 2) {
return 0;
}else{
return 0;
}
printf("\n");
system("PAUSE");
return 0;
} |