0

Hey,

I needed to delete a file created by a child process and our prof suggested that I use the system() command to do so. I 'manned' system but cant find anything useful on how to use it to delete an opened file. Can anyone suggest as to how this could be done?

Thanks,
Kunal.

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by marco93
0

You just use the command string as the argument, so (in unix) to delete "/mypath/myfile", you do:

system("/usr/bin/rm /mypath/myfile");

I tend to use the path when I know it, but:

system("rm myfile");

might do as well.

In Windows, use "del", not "rm", and don't forget that a backslash is a meta-character, so in a path you'd use "\\".

Edited by dan63043: Mention backslash

0

You just use the command string as the argument, so (in unix) to delete "/mypath/myfile", you do:

system("/usr/bin/rm /mypath/myfile");

I tend to use the path when I know it, but:

system("rm myfile");

might do as well.

In Windows, use "del", not "rm", and don't forget that a backslash is a meta-character, so in a path you'd use "\\".

Thanks a lot.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.