jejefull1234
Messages postés8Date d'inscriptiondimanche 6 mars 2011StatutMembreDernière intervention15 mars 2011
-
14 mars 2011 à 21:17
jejefull1234
Messages postés8Date d'inscriptiondimanche 6 mars 2011StatutMembreDernière intervention15 mars 2011
-
15 mars 2011 à 15:38
Bonjour,
J'ai réaliser un programme qui affiche la date de création d'un fichier .txt
Le problème c'est que mon code fonctionne en debug mais plante en exécution console.
int main(int argc, char *argv[])
{
HANDLE Fct1;
WIN32_FIND_DATA(x);
LPCTSTR Dossier = "C:\\Users\\...\\history\\essai\\*.*";
char* i;
Fct1 = FindFirstFile(Dossier, &x);
if(Fct1 == INVALID_HANDLE_VALUE)
{
printf("Erreur de listing");
}
else
{
printf("*** Affichage date fichier txt *** : \n\n");
do
{
char repert[100]="C:\\Users\\...\\history\\essai\";
i = strstr(x.cFileName,".txt"); // cherche les fichiers .txt
if( i != NULL) // Si ce sont des fichier texte faire ...
{
strcat(repert,x.cFileName); // chemin + nom de fichier
DateFile(repert); // Fonction qui récupère et affiche la date de création
}
}while(FindNextFile(Fct1,&x));
CloseHandle(Fct1);
}
return 0;
}
BruNews
Messages postés21040Date d'inscriptionjeudi 23 janvier 2003StatutModérateurDernière intervention21 août 2019 14 mars 2011 à 22:24
Je ne teste pas mais devrait aller.
char Dossier[] = "C:\\Users\\...\\history\\essai\\*.*";
int main(int argc, char *argv[])
{
HANDLE Fct1;
WIN32_FIND_DATA wfd;
char buf[2048];
char *c, *d, *p;
FILETIME ft;
SYSTEMTIME st;
Fct1 = FindFirstFile(Dossier, &wfd);
if(Fct1 == INVALID_HANDLE_VALUE) {
printf("Erreur de listing");
return 0;
}
printf("*** Affichage date fichier txt *** : \n\n");
c = Dossier;
d = buf;
while(*d = *c) {c++; d++;} // d EST POINTEUR DE CHAINAGE
do {
// i = strstr(x.cFileName,".txt"); // cherche les fichiers .txt
// NON, c'est au cul du nom qu'on verifie et SEULEMENT au cul.
c = x.cFileName;
p = d; // ON CHAINE DIRECT, AINSI ON AURA LE PTR FINAL POUR VERIF DE ".txt"
while(*p = *c) {c++; p++;}
// CreateFile() et GetFileTime() INUTILES
if(*((DWORD*) (p - 4)) == 0x7478742E) { // '.txt' ou 0x7478742E, c'est idem.
FileTimeToLocalFileTime(&wfd.ftCreationTime, &ft);
FileTimeToSystemTime(&ft, &st);
// TES printf D'AFFICHAGE ICI
}
} while(FindNextFile(Fct1, &wfd));
FindClose(Fct1); // NIET CloseHandle()
return 0;
}