I am new to unix and c++.. here's my problem: I have some files constantly generated in seq like
ABU030227154405 ABU030227154910 ABU030227165702
i need to find the files which match some string like "227" and delete all the files that have that string in the filename.. its like "rm ABU03227* ".... how do i do it ?? i am kind of lost. there are 2 methods i could think of one using remove() and the other through system().. anyone with a good clean code to solve this ??
void delete_file( )
{
int cur_year, cur_month, cur_day;
struct tm *time_ptr;
time_t lt;
lt = time('\0');
bool leapyear;
int total_days;
int days[13] ={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
time_ptr =localtime(<);
cur_year = time_ptr->tm_year +1900;
cur_month = time_ptr->tm_mon +1;
cur_day =time_ptr->tm_mday;
/*
//find all files matching substr
//get the name of those files
if (remove(files)!= 0){
cout <<"cant removed file \n";
}
*/
string rmstr(" rm "
;
string filestr("ABU030227*"
;
string remove_cmd = rmstr + filestr;
cout <<"the STRING IS ="<<remove_cmd<<endl;
if(system(remove_cmd.c_str())== -1){
cout <<"cant removed file \n";
}
}
ABU030227154405 ABU030227154910 ABU030227165702
i need to find the files which match some string like "227" and delete all the files that have that string in the filename.. its like "rm ABU03227* ".... how do i do it ?? i am kind of lost. there are 2 methods i could think of one using remove() and the other through system().. anyone with a good clean code to solve this ??
void delete_file( )
{
int cur_year, cur_month, cur_day;
struct tm *time_ptr;
time_t lt;
lt = time('\0');
bool leapyear;
int total_days;
int days[13] ={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
time_ptr =localtime(<);
cur_year = time_ptr->tm_year +1900;
cur_month = time_ptr->tm_mon +1;
cur_day =time_ptr->tm_mday;
/*
//find all files matching substr
//get the name of those files
if (remove(files)!= 0){
cout <<"cant removed file \n";
}
*/
string rmstr(" rm "
string filestr("ABU030227*"
string remove_cmd = rmstr + filestr;
cout <<"the STRING IS ="<<remove_cmd<<endl;
if(system(remove_cmd.c_str())== -1){
cout <<"cant removed file \n";
}
}