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
|
/*
============================================================================
Name : source.c
Date : 05/02/2017
Author : SAMBIA39
Version : 0.1
Copyright : Copyright © 2017 SAMBIA39 All rights reserved.
Description : Ansi-style
============================================================================
*/
#define REP_DEFAULT "/Users/DebugUser/Desktop/REP_TEST/"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
void f_scan_print_rep( char *ptr_name,
int id ){
DIR *pDir;
struct dirent *pEntryInode;
struct stat info;
extern int errno;
errno = 0;
if( NULL == ( pDir = opendir(ptr_name)) ){
fprintf( stderr, "(%d)\t:%s:%s\n\t:%s\n", errno,
"impossible d'ouvrir le repertoire:", ptr_name,
strerror(errno) );
return;
}
chdir( ptr_name );
while( NULL != (pEntryInode = readdir(pDir) ) ){
lstat(pEntryInode->d_name, &info );
/*
* Si Répertoire trouvé mais "." & ".."
* sont ignioré.
*/
if( S_ISDIR(info.st_mode) ){
if( (0 == strcmp(".", pEntryInode->d_name)) ||
(0 == strcmp("..", pEntryInode->d_name)) )
continue;
/* En affiche le répertoire */
fprintf( stdout, "%*s%s/ est un dossier\n", id,"", pEntryInode->d_name );
/*
* Appel récursive à une nouvelle entrer
*/
f_scan_print_rep(pEntryInode->d_name, id+4 );
/*
* Sinon-si ce n'est pas un répertoire alors on teste
* si c'est un fichier executable avec les droit utilisateur
* ou un fichier.
*/
}else{
if( (!S_ISDIR( info.st_mode)) &&
((info.st_mode & S_IRWXU) == S_IRWXU) ){
fprintf( stdout, "%*s%s est un fichiers executable\n", id, "",
pEntryInode->d_name );
}else if( !S_ISDIR( info.st_mode) )
fprintf( stdout, "%*s%s est un fichiers\n", id, "",
pEntryInode->d_name );
}
}
chdir("..");
closedir(pDir);
}
int main( int argc, char **argv ){
f_scan_print_rep( REP_DEFAULT, 0 );
return EXIT_SUCCESS;
} |
Partager