Delete file in c or c++

Nov 6, 2011 at 10:33am
I want to delete a folder or file at a specific location using c or c++..............how can i do that
Nov 6, 2011 at 11:28am
Try remove, for a file.

http://www.cplusplus.com/reference/clibrary/cstdio/remove/

If you're using a POSIX friendly OS, you can use rmdir from unistd.h to delete a directory.

http://pubs.opengroup.org/onlinepubs/007908799/xsh/rmdir.html

If you're using a non-POSIX OS, you'll have to check your OS documentation. Win comes with DeleteDirectory, I seem to recall.
Last edited on Nov 6, 2011 at 11:54am
Nov 6, 2011 at 2:00pm
With WIN32 it's DeleteFile but RemoveDirectory (to remove an empty directory).

For Windows, as well as RemoveDirectory, you have Visual C++'s _rmdir() -- they've added an underscore prefix to all these kinds of calls (_mkdir, _chdir, ...)

There's also _unlink() cf. Linux's unlink().

Andy

P.S. MSDN says:
This POSIX function is deprecated beginning in Visual C++ 2005. Use the ISO C++ conformant _rmdir instead.


Topic archived. No new replies allowed.