If i dont know whether a file is exist.If it exist i will do something depend on the content in that file.The file could be in .txt or .gz format and the file can also not exist. Below is my code:
//Check whether is a zip file
char *pre_pcom_file_copy = new char[strlen(pre_pat_file)+7];
strcpy (pre_pcom_file_copy,pre_pcom_file);
strcat (pre_pcom_file_copy,".gz");
char *cmd = new char[strlen("gzip -dc ")+strlen(pre_pcom_file_copy)+1];
strcpy (cmd,"gzip -dc ");
strcat (cmd,pre_pcom_file_copy);
if ( (pre_pcom = popen(cmd,"r")) == NULL ){
//Do nothing
}else{
cout << "Parsing pre.pcomments file --->" << pre_pcom_file << endl;
pcomyyin = pre_pcom;
if(_vecTime.size() > 0){
//for pre_pcom _vecTime should be empty
pcom_time = _vecTime[_vecTime.size()-1];
}
first_time = 1; // make sure tester cycle start from 0 from pcomment file
pcomyyparse ();
pclose(pre_pcom);
//delete [] cmd;
cout << "Parsing pre.pcomments file DONE!" << endl;
}
I want to check a file that has the same name with a must have file for example hello.abc but the file i want to check could be hello.abc or hello.gz or even not exist.If i do in the way like above i got error when the file hello.txt or hello.gz are totally not exist.How can i solve this?