Is there a reason you are not using the unlink system call? Also, I am unfamiliar with the 1.t , etc constructs, can you explain what this does, or what you are expecting it to do?
The problem in removing is the string read like this /usr1/mydir/1.t2.t3.t.
My requirement is to remove file 1.t,2.t and 3.t .
The path is same only file name is different.
The files removed like this
rm -f /usr1/mydir/1.t
rm -f /usr1/mydir/2.t
rm -f /usr1/mydir/3.t
Its still having same issue.
I just print the string ,now its looks /bin/rm -f /usr1/mydir/1.t,2.t,3.t.
No removal is done.
sprintf (cmd, "/bin/rm -f %s,%s,%s","/usr1/mydir/", "1.t","2.t","3.t");
The contents of cmd, after the [man]sprintf[/man] would be: /bin/rm -f /usr1/mydir/,1.t,2.t , which is not what is needed to remove a file. This does what you want:
{
char path[100];
char *file[3] = { "1.t", "2.t", "3.t"; }
for (int i = 0; i < 3; i++) {
strcpy(path, "/usr1/mydir/");
strcat(path, file);
unlink(path);
}
}
Thank you all,
Now its working fine:)
I also tried like this that also working.
sprintf (cmd, "/bin/rm -f %s%s %s %s","/usr1/mydir/", "1.t","2.t","3.t");