19 if(fileName ==
"")
return false;
20 return access(fileName.c_str(), F_OK) != -1;
28 if(fileName ==
""){
return false;}
29 struct stat path_stat;
30 if(stat(fileName.c_str(), &path_stat) != 0){
33 return S_ISREG(path_stat.st_mode) != 0;
42 std::string
getExistingFileName(
const std::string & fileName,
const std::vector<std::string> & vecDirectory){
43 if(vecDirectory.size() == 0lu || fileName ==
""){
return "";}
44 std::vector<std::string>::const_iterator it(vecDirectory.begin());
45 while(it != vecDirectory.end()){
46 std::string tmpFile(*it +
"/" + fileName);
58 if(dirName ==
""){
return false;}
59 struct stat path_stat;
60 if(stat(dirName.c_str(), &path_stat) != 0){
63 return S_ISDIR(path_stat.st_mode) != 0;
71 char* ptr = get_current_dir_name();
85 if(path ==
""){
return false;}
86 return path[0] ==
'/';
95 else if(path[0] ==
'/'){
return path;}
106 std::vector<std::string> vecOut;
107 for(std::vector<std::string>::const_iterator it(vecPath.begin()); it != vecPath.end(); ++it){
118 if(path ==
""){
return path;}
119 if(path.front() ==
'.'){
return path;}
121 std::list<std::string>::reverse_iterator rit = listDir.rbegin();
122 while(rit != listDir.rend()){
123 if(*rit ==
"." || *rit ==
""){
126 }
else if(*rit ==
".."){
130 if(rit != listDir.rend()){
140 std::string out(
""), separator(
"");
144 for(std::list<std::string>::iterator it(listDir.begin()); it != listDir.end(); ++it){
145 if(*it ==
""){
continue;}
146 out += separator + (*it);
157 std::string buffer(
"");
159 std::string::const_reverse_iterator rit = fileName.rbegin();
160 while(rit != fileName.rend()){
162 buffer = *rit + buffer;
164 find = (*rit ==
'/');
176 std::string
getUnderPath(
const std::string & fileName,
const std::string & pathPart){
177 if(pathPart ==
""){
return fileName;}
178 std::list<std::string> listDir(
cutStringList(fileName,
'/'));
179 std::list<std::string>::iterator it(listDir.begin());
181 while(isSearch && it != listDir.end()){
182 isSearch = *it != pathPart;
185 std::string out(
""), separator(
"");
186 while(it != listDir.end()){
187 out += separator + (*it);
199 std::vector<std::string>
getUnderPath(
const std::vector<std::string> & vecFileName,
const std::string & pathPart){
200 std::vector<std::string> vecOut;
201 for(std::vector<std::string>::const_iterator it(vecFileName.begin()); it != vecFileName.end(); ++it){
213 FILE* fp = fopen(fileName.c_str(),
"r");
214 if(fp == NULL || expectedBegining.size() == 0lu){
return false;}
218 while(isMatch && !feof(fp) && i < expectedBegining.size()){
220 isMatch = (char)val == expectedBegining[i];
232 std::string buffer(
"");
233 std::string::const_reverse_iterator rit = fileName.rbegin();
234 while(rit != fileName.rend()){
235 if(*rit ==
'/')
break;
236 buffer = *rit + buffer;
247 std::string buffer(
"");
248 std::string::const_reverse_iterator rit = path.rbegin();
249 while(rit != path.rend()){
258 buffer = *rit + buffer;
269 FILE * fp = fopen(filename.c_str(),
"r");
271 std::cerr <<
"getFileContent : cannot open file '" << filename <<
"'" << std::endl;
284 if(fp == NULL)
return "";
285 std::string bufferAllFile(
"");
289 if(buffer != EOF) bufferAllFile += (char)buffer;
292 return bufferAllFile;
301 FILE * fp = fopen(filename.c_str(),
"w");
303 std::cerr <<
"saveFileContent : cannot open file '" << filename <<
"'" << std::endl;
317 if(fp == NULL)
return false;
318 fprintf(fp,
"%s", content.c_str());
328 std::string extention(
"");
330 std::string::const_reverse_iterator rit(fileName.rbegin());
331 while(run && rit != fileName.rend()){
332 if(*rit ==
'.' || *rit ==
'/') run =
false;
333 else extention = *rit + extention;
345 if(nbPoint == 0lu)
return "";
346 std::string extention(
""), tmpExtention(
""), middleDot(
"");
348 std::string::const_reverse_iterator rit(fileName.rbegin());
349 while(run && rit != fileName.rend()){
350 if(*rit ==
'/'){run =
false;}
351 else if(*rit ==
'.'){
352 extention = tmpExtention + middleDot + extention;
356 tmpExtention = *rit + tmpExtention;
370 if(nbPoint == 0)
return fileName;
371 std::string buffer(
"");
373 std::string::const_iterator it = fileName.begin();
374 while(it != fileName.end() && findNbPoint < nbPoint){
377 if(findNbPoint < nbPoint){
394 if(longestExtention !=
""){
395 return copyStr(fileName, 0lu, fileName.size() - (longestExtention.size() + 1lu));
407 std::string tmpDirName(
"");
408 bool isNotFirst(
false);
409 for(std::list<std::string>::iterator it(listDir.begin()); it != listDir.end(); ++it){
414 if(tmpDirName !=
""){
416 if(mkdir(tmpDirName.c_str(), 0755) != 0){
417 cerr <<
"createDirectoryIfNotExist : can't create directory '" << tmpDirName <<
"'" << endl;