Qwert999
Nuovo Utente
- Messaggi
- 10
- Reazioni
- 0
- Punteggio
- 26
ciao a tutti , sto facendo un programma che cerca ricorsivamente i file con una certa estensione contenuti in una directory che viene passata dal terminale...il problema che ho è che la ricerca di un dato file si arresta nella cartella che gli viene passata , non trovando altri file in eventuali subdirectory...come posso fare ?
ps se notate altri errori dite pure!
ps se notate altri errori dite pure!
C:
#include<stdio.h>
#include<sys/stat.h>
#include<errno.h>
#include<stdlib.h>
#include<dirent.h>
#include<stdarg.h>
#include<limits.h>
#include<string.h>
#include<time.h>
void ricor1(const char estensione[],const char nomedirectory[]){
struct stat attr;
char dbuf[PATH_MAX+1];
DIR * fh ;//puntatore ad una struttura DIR
struct dirent *fdata;
struct stat buf;
if((fh=opendir(nomedirectory))==NULL){
perror("ERRORE 1");
exit(errno);
}
puts("\nElenco directory:\n");
while((fdata = readdir (fh))!=NULL){
if(strstr(fdata->d_name,estensione)){
realpath(fdata->d_name,dbuf);
printf("[%s]",dbuf);
stat(nomedirectory,&attr);
printf("%s\n",ctime(&attr.st_mtime));
}
}
}
void ricor2(const char estensione[]){
struct stat attr;
char dbuf[PATH_MAX+1];
DIR * fh ;//puntatore ad una struttura DIR
struct dirent *fdata;
struct stat buf;
if((fh=opendir("./"))==NULL){
perror("ERRORE 1");
exit(errno);
}
while((fdata = readdir (fh))!=NULL){
if(strstr(fdata->d_name,estensione)){
realpath(fdata->d_name,dbuf);
printf("[%s]",dbuf);
stat("./",&attr);
printf("%s\n",ctime(&attr.st_mtime));
}
}
}
int main(int argc, char *argv[])
{
if(argc==3){
printf("Controllo esistenza directory.. \n");
DIR* dir=opendir(argv[2]);
if(dir){
ricor1(argv[1],argv[2]);
} else if (ENOENT==errno){
printf("La directory passata non esiste");
}
else{
printf("altro errore"); } }
else if(argc==2){
ricor2(argv[1]);
}
}