when I construct a string
string s ="";
s = rb.rep + a.chemin.substr(rep.size());
//cout << "s:" << s << endl;
if (s.empty()){
cerr<<"c++ string is uninitialized"<<endl;
exit(1);
}
and doing
if(is_file(s)){
a.s="ok";
}
else{
SEULS.push_back(ela.first);
a.s="SEUL";
}
with this function:
bool is_file(string &path) {
the structure is defined
struct stat buf;
stat(path.c_str(), &buf);
you know if it is a file or not
if(S_ISREG(buf.st_mode)) cout<<"is_file "<<path<<" "<<S_ISREG(buf.st_mode)<<endl;
else cout<<"NO is_file "<<path<<" "<<S_ISREG(buf.st_mode)<<endl
another way is trying to open the file
FILE*f=fopen(path.c_str(), "r");
if( f == NULL){
cerr<<"PROB fopen "<<path<<endl;
exit (EXIT_FAILURE);
}
else{
fclose(f);
}
the result is returned
return S_ISREG(buf.st_mode);
}
I got this result on console
is_file e/rep_A/1.txt 1
NO is_file e/2.txt 0
PROB fopen e/2.txt
Program ended with exit code: 1
but when I comment
// FILE*f=fopen(path.c_str(), "r");
// if( f == NULL){
// cerr<<"PROB fopen "<<path<<endl;
// exit (EXIT_FAILURE);
// }
// else{
// fclose(f);
// }
I got
is_file e/2.txt 1
is_file e/rep_B/3.txt 1
lesSeuls de e et de a...
is_file a/rep_A/1.txt 1
is_file a/rep_B/3.txt 1
PROBLEM:
e/2.txt doesn't exists !!
and if I uncomment
cout << "s:" << s << endl;
before calling
if(is_file(s)){
a.s="ok";
}
else{
That's ok !
I get
NO is_file e/2.txt 0
PROB fopen e/2.txt
Program ended with exit code: 1
To result I have to print string s or printing something to get the good string s. it is like concurrent programming.
This is not a joke
Did you meet that?
Thanks
exit(1); } I get the good result : stat: No such file or directory File name: e/2.txt. I have seen https://stackoverflow.com/questions/3512434/using-struct-stat Thanks !! – user7058377 Sep 09 '18 at 18:13