By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,705 Members | 2,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,705 IT Pros & Developers. It's quick & easy.

How do I delete files from a directory?

P: n/a
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.
Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
In message <if********************@comcast.com>, Sonoman
<no****@microsoft.com> writes
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?
You should use the scripting language provided by your operating system.
Please advise.


This is not something that can be done using standard C++.

--
Richard Herring
Jul 22 '05 #2

P: n/a
On Wed, 30 Jun 2004 11:32:42 -0400
"Sonoman" <no****@microsoft.com> wrote:
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 an*****@slashdot.ch
tcp/6667 irc.slashdot.ch #garbage
Jul 22 '05 #3

P: n/a
Sonoman,

"Sonoman" <no****@microsoft.com> wrote in message
news:if********************@comcast.com...
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.


See http://www.boost.org/libs/filesystem...htm#remove_all.

Jeff F

Jul 22 '05 #4

P: n/a
On Wed, 30 Jun 2004 11:32:42 -0400, "Sonoman" <no****@microsoft.com>
wrote:
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.


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
Jul 22 '05 #5

P: n/a
On Wed, 30 Jun 2004 19:05:55 +0200, Andreas Baumgart
<an*****@slashdot.ch> wrote in comp.lang.c++:
On Wed, 30 Jun 2004 11:32:42 -0400
"Sonoman" <no****@microsoft.com> wrote:
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.
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/~a...FAQ-acllc.html
Jul 22 '05 #6

P: n/a
In message <3e********************************@4ax.com>, Jack Klein
<ja*******@spamcop.net> writes
On Wed, 30 Jun 2004 19:05:55 +0200, Andreas Baumgart
<an*****@slashdot.ch> wrote in comp.lang.c++:
On Wed, 30 Jun 2004 11:32:42 -0400
"Sonoman" <no****@microsoft.com> wrote:
> 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
Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.