00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "SurcoucheRepertoire.h"
00012
00013 DIRECTORY DirOpen(char *pDirName, char *pFirstData, int *pIsFile)
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 }
00059
00060 int DirClose(DIRECTORY *pDir)
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 }
00072
00073 int DirGetNext(DIRECTORY *pDir, char *pNextData, int *pIsFile)
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 }
00114
00115 int DirCreate(char *pName)
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 }
00130
00131 int DirDelete(char *pName)
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 }
00143