Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How do I delete files from a directory?

Reply
Thread Tools

How do I delete files from a directory?

 
 
Sonoman
Guest
Posts: n/a
 
      06-30-2004
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.


 
Reply With Quote
 
 
 
 
Richard Herring
Guest
Posts: n/a
 
      06-30-2004
In message <>, Sonoman
<> 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
 
Reply With Quote
 
 
 
 
Andreas Baumgart
Guest
Posts: n/a
 
      06-30-2004
On Wed, 30 Jun 2004 11:32:42 -0400
"Sonoman" <> 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
tcp/6667 irc.slashdot.ch #garbage
 
Reply With Quote
 
Jeff Flinn
Guest
Posts: n/a
 
      06-30-2004
Sonoman,

"Sonoman" <> wrote in message
news:...
> 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



 
Reply With Quote
 
rossum
Guest
Posts: n/a
 
      06-30-2004
On Wed, 30 Jun 2004 11:32:42 -0400, "Sonoman" <>
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
 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      07-01-2004
On Wed, 30 Jun 2004 19:05:55 +0200, Andreas Baumgart
<> wrote in comp.lang.c++:

> On Wed, 30 Jun 2004 11:32:42 -0400
> "Sonoman" <> 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
 
Reply With Quote
 
Richard Herring
Guest
Posts: n/a
 
      07-01-2004
In message <>, Jack Klein
<> writes
>On Wed, 30 Jun 2004 19:05:55 +0200, Andreas Baumgart
><> wrote in comp.lang.c++:
>
>> On Wed, 30 Jun 2004 11:32:42 -0400
>> "Sonoman" <> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
FAQ 5.38 Why does Perl let me delete read-only files? Why does "-i" clobber protected files? Isn't this a bug in Perl? PerlFAQ Server Perl Misc 0 03-09-2011 11:00 PM
FAQ 5.38 Why does Perl let me delete read-only files? Why does "-i" clobber protected files? Isn't this a bug in Perl? PerlFAQ Server Perl Misc 0 02-11-2011 05:00 AM
Can someone tell me why I can't delete this file? and why it blue screens WinXP Pro on delete? zZz Computer Support 1 01-12-2005 02:37 AM
Cannot Delete, (The Delete Key Won't Work) Lee Something Computer Support 13 10-15-2003 09:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57