#include <string.h>
#include <malloc.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
Aller au code source de ce fichier.
Fonctions | |
| DIRECTORY | DirOpen (char *pDirName, char *pFirstData, int *pIsFile) |
| Ouvre un dossier. | |
| int | DirClose (DIRECTORY *pDir) |
| Ferme un dossier. | |
| int | DirGetNext (DIRECTORY *pDir, char *pNextData, int *pIsFile) |
| Récupère une donnée d'un dossier. | |
| int | DirCreate (char *pName) |
| Crée un repertoire. | |
| int | DirDelete (char *pName) |
| Supprime un repertoire. | |
Définition dans le fichier SurcoucheRepertoire.h.
|
|
Ferme un dossier explorer.
Définition à la ligne 60 du fichier SurcoucheRepertoire.cpp. 00061 {
00062 #ifdef WIN32
00063 if(FindClose(pDir))
00064 return 0;
00065 #else
00066 if(!closedir(*pDir))
00067 return 0;
00068 #endif
00069
00070 return 1;
00071 }
|
|
|
Crée un repertoire via l'os.
Définition à la ligne 115 du fichier SurcoucheRepertoire.cpp. 00116 {
00117 #ifdef WIN32
00118 if(CreateDirectory(pName, NULL))
00119 return 0;
00120 #else
00121 mode_t modes;
00122
00123 modes = S_IRWXU | S_IXGRP | S_IXOTH;
00124 if(!mkdir(pName, modes))
00125 return 0;
00126 #endif
00127
00128 return 1;
00129 }
|
|
|
Supprime un repertoire vide via l'os.
Définition à la ligne 131 du fichier SurcoucheRepertoire.cpp. 00132 {
00133 #ifdef WIN32
00134 if(RemoveDirectory(pName))
00135 return 0;
00136 #else
00137 if(!rmdir(pName))
00138 return 0;
00139 #endif
00140
00141 return 1;
00142 }
|
|
||||||||||||||||
|
Récupère la donnée suivante d'un dossier.
Définition à la ligne 73 du fichier SurcoucheRepertoire.cpp. 00074 {
00075 #ifdef WIN32
00076 WIN32_FIND_DATA Find;
00077 #else
00078 struct dirent *Find;
00079 struct stat Stat;
00080 #endif
00081
00082 *pNextData = '\0';
00083 *pIsFile = 1;
00084
00085 #ifdef WIN32
00086 if(FindNextFile(pDir, &Find))
00087 {
00088 if(Find.cFileName)
00089 strcpy(pNextData, Find.cFileName);
00090
00091 if(Find.dwFileAttributes)
00092 if(Find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
00093 *pIsFile = 0;
00094 return 0;
00095 }
00096 #else
00097 Find = readdir(*pDir);
00098 if(Find)
00099 {
00100 Find = readdir(*pDir);
00101 if(Find->d_name)
00102 strcpy(pNextData, Find->d_name);
00103
00104 lstat(pNextData, &Stat);
00105 if(S_ISDIR(Stat.st_mode))
00106 *pIsFile = 0;
00107
00108 return 0;
00109 }
00110 #endif
00111
00112 return 1;
00113 }
|
|
||||||||||||||||
|
Ouvre un dossier pour l'explorer et recupère la première donnée.
Définition à la ligne 13 du fichier SurcoucheRepertoire.cpp. 00014 {
00015 char *DirName;
00016 DIRECTORY Dir;
00017 #ifdef WIN32
00018 WIN32_FIND_DATA Find;
00019 #else
00020 struct dirent *Find;
00021 struct stat Stat;
00022 #endif
00023
00024 DirName = (char *)malloc(sizeof(char) * (strlen(pDirName) + 3));
00025 strcpy(DirName, pDirName);
00026 strcat(DirName, "\\");
00027 strcat(DirName, "*");
00028 *pFirstData = '\0';
00029 *pIsFile = 1;
00030
00031 #ifdef WIN32
00032 if(Dir = FindFirstFile(DirName, &Find))
00033 {
00034 if(Find.cFileName)
00035 strcpy(pFirstData, Find.cFileName);
00036
00037 if(Find.dwFileAttributes)
00038 if(Find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
00039 *pIsFile = 0;
00040 }
00041 #else
00042 Dir = opendir(DirName);
00043 if(Dir)
00044 {
00045 Find = readdir(Dir);
00046 if(Find->d_name)
00047 strcpy(pFirstData, Find->d_name);
00048
00049 lstat(DirName, &Stat);
00050 if(S_ISDIR(Stat.st_mode))
00051 *pIsFile = 0;
00052 }
00053 #endif
00054
00055 free(DirName);
00056
00057 return Dir;
00058 }
|
1.3.9.1