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.

Recommended Answers

All 3 Replies

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 "\\".

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.

Never use System()
It's prohibited in Production environment, in particular on Windows...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.