Discussion:
How do I delete files from a directory?
(too old to reply)
Sonoman
2004-06-30 15:32:42 UTC
Permalink
Hi all:
I would like to find out how to write a small program that deletes files. I
want to be able to delete all files from a known directory (i.e. cookies,
temp files, etc.) regardless of type and name, "or" may be by extension.
This way I could have it run on start up and I will have my computer free of
junk every time I reboot. What should I use? Please advise.
Richard Herring
2004-06-30 16:17:42 UTC
Permalink
Post by Sonoman
I would like to find out how to write a small program that deletes files. I
want to be able to delete all files from a known directory (i.e. cookies,
temp files, etc.) regardless of type and name, "or" may be by extension.
This way I could have it run on start up and I will have my computer free of
junk every time I reboot. What should I use?
You should use the scripting language provided by your operating system.
Post by Sonoman
Please advise.
This is not something that can be done using standard C++.
--
Richard Herring
Andreas Baumgart
2004-06-30 17:05:55 UTC
Permalink
On Wed, 30 Jun 2004 11:32:42 -0400
Post by Sonoman
I would like to find out how to write a small program that deletes files. I
want to be able to delete all files from a known directory (i.e. cookies,
temp files, etc.) regardless of type and name, "or" may be by
extension.
The way you delete files from a filesystem normally depends on the
syscalls your os provides. So there is no clear way to do this.

On Linux systems there is a syscall "unlink" which can do that. There
also exists an accordant function unlink() in the libc. I am quite sure
there exists a similar library for Windows, too.

Greets,
Andreas
--
tcp/80 http://andreas.slashdot.ch
tcp/25 ***@slashdot.ch
tcp/6667 irc.slashdot.ch #garbage
Jack Klein
2004-07-01 02:43:13 UTC
Permalink
On Wed, 30 Jun 2004 19:05:55 +0200, Andreas Baumgart
Post by Andreas Baumgart
On Wed, 30 Jun 2004 11:32:42 -0400
Post by Sonoman
I would like to find out how to write a small program that deletes files. I
want to be able to delete all files from a known directory (i.e. cookies,
temp files, etc.) regardless of type and name, "or" may be by extension.
The way you delete files from a filesystem normally depends on the
syscalls your os provides. So there is no clear way to do this.
Apparently you are unaware of the standard C++ library function
std::remove() prototyped in <cstdlib>, which may also be invoked as
::remove() by including <stdlib.h>.

These have been part of the ISO C standard for 15 years now, and part
of ISO C++ for nearly 6 years. They work on all conforming hosted
implementations, and that includes Linux and Windows.
Post by Andreas Baumgart
On Linux systems there is a syscall "unlink" which can do that. There
also exists an accordant function unlink() in the libc. I am quite sure
there exists a similar library for Windows, too.
Greets,
Andreas
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
Richard Herring
2004-07-01 09:20:09 UTC
Permalink
Post by Jack Klein
On Wed, 30 Jun 2004 19:05:55 +0200, Andreas Baumgart
Post by Andreas Baumgart
On Wed, 30 Jun 2004 11:32:42 -0400
Post by Sonoman
I would like to find out how to write a small program that deletes files. I
want to be able to delete all files from a known directory (i.e. cookies,
temp files, etc.) regardless of type and name, "or" may be by extension.
The way you delete files from a filesystem normally depends on the
syscalls your os provides. So there is no clear way to do this.
Apparently you are unaware of the standard C++ library function
std::remove() prototyped in <cstdlib>, which may also be invoked as
::remove() by including <stdlib.h>.
Ahem. The OP wants to delete _all_ files, not a single named file. I
don't think you can use std::remove() to do that, without some
system-dependent support to enumerate the files.
--
Richard Herring
Jeff Flinn
2004-06-30 17:43:04 UTC
Permalink
Sonoman,
Post by Sonoman
I would like to find out how to write a small program that deletes files. I
want to be able to delete all files from a known directory (i.e. cookies,
temp files, etc.) regardless of type and name, "or" may be by extension.
This way I could have it run on start up and I will have my computer free of
junk every time I reboot. What should I use? Please advise.
See http://www.boost.org/libs/filesystem/doc/operations.htm#remove_all.

Jeff F
rossum
2004-06-30 22:05:42 UTC
Permalink
Post by Sonoman
I would like to find out how to write a small program that deletes files. I
want to be able to delete all files from a known directory (i.e. cookies,
temp files, etc.) regardless of type and name, "or" may be by extension.
This way I could have it run on start up and I will have my computer free of
junk every time I reboot. What should I use? Please advise.
I suggest you look at the remove(const char *filename) function in
cstdio which might be what you want.

rossum



--

The Ultimate Truth is that there is no Ultimate Truth
Loading...