Quick Search for:  in language:    
came,with,problem,work,needed,delete,more,tha
   Code/Articles  |  Newest/Best  |  Community  |  Jobs  |  Other  |  Goto  | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Perl Stats

 Code: 74,273. lines
 Jobs: 24. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login





Latest Code Ticker for Perl.
Click here to see a screenshot of this code!CGIScripter
By David Simpson on 11/24

(Screen Shot)

Calender
By Jeff Mills on 11/20


quikpoll
By Jeff Mills on 11/20


Encrypt Password
By Jeff Mills on 11/20


Rock, Paper, Scissors w/ GUI
By Kurt Rudolph on 11/19


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Multiple Files delete

Print
Email
 
VB icon
Submitted on: 9/15/2003 12:29:42 PM
By: Forunculo 
Level: Beginner
User Rating: Unrated
Compatibility:5.0 (all versions)

Users have accessed this code 1096 times.
 
(About the author)
 
     I came up with this problem at my work. I needed to delete more than 1000 files at once, but rm -f *.* would not do it cause of the quantity, so i made this little program. Great for beginers.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

    =**************************************
    = for :Multiple Files delete
    =**************************************
    You may use this as you want. 
    don't change second line please.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    =**************************************
    = Name: Multiple Files delete
    = Description:I came up with this proble
    =     m at my work. I needed to delete more th
    =     an 1000 files at once, but rm -f *.* wou
    =     ld not do it cause of the quantity, so i
    =     made this little program. Great for begi
    =     ners.
    = By: Forunculo
    =
    =This code is copyrighted and has    = limited warranties.Please see http://w
    =     ww.Planet-Source-Code.com/vb/scripts/Sho
    =     wCode.asp?txtCodeId=537&lngWId;=6    =for details.    =**************************************
    
    #!/usr/bin/perl
    #By Forunculo
    #thanks to Ney
    $folder="/var/spool/clientmqueue/"; #directory to be deleted
    %files = ();
    $x=0;
    opendir(DIR, $folder); #open the directory for reading
    foreach(readdir(DIR)) #read from the directory
    {
    $file=$_;
    if (-d $folder.$file) #if it's a folder don't count it
    {
    }
    else
    {
    $files{$x} = $file; # add each file to the hash
    $x++;
    }
    }
    if ($x eq 0) #if there are no files on the directory
    {
    print "\nThe directory you specified is empty\n\n";
    exit;
    }
    print "You are going to delete $x files\n";
    print "Press S to show the files or D to delete Q to quit : ";
    $x=0;
    $ans = <STDIN>;
    if ($ans eq "S\n" or $ans eq "s\n") #if yes, just display the hash
    {
    foreach (keys %files)
    {
    print "$files{$x}\n";
    $x++;
    }
    print "\nDo you still want to delete them? ";
    $anse = <STDIN>;
    if ($anse eq "Y\n" or $anse eq "y\n")
    {
    deleteme()
    }
    }
    if ($ans eq "D\n" or $ans eq "d\n")
    {
    deleteme()
    }
    else
    {
    print "\nNo files were deleted\n";
    }
    #-----------------Sub----------------
    #This baby does all the work
    sub deleteme
    {
    $x=0;
    foreach (keys %files)
    {
    print "Deleting file $files{$x}\n"; #print the name of the file
    unlink ("$folder$files{$x}"); #delete it
    $x++;
    }
    print "\nDone deleting files. Total files deleted : $x\n";
    exit;
    }

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
9/15/2003 3:50:13 PM:Forunculo
i wonder by the indent did not come up.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/16/2003 9:31:42 AM:
What about 
xargs?
http://www.itworld.com/nl/unix
_insider/07312003/
http://unix.about.co
m/library/weekly/aa082001a.htm
http://w
ww.samag.com/documents/s=8228/sam0306g/0
306g.htm
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/16/2003 7:05:40 PM:Forunculo
You can easily add to the code so that 
you can pass the directory by an 
argument. i will do it and post it for 
you. 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/20/2003 11:31:23 AM:
I mean, why use your Perl script, if 
you can deal with large number of files 
using find and xargs?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/11/2003 1:22:01 AM:Forunculo
The intention of the code is not to 
delete multiple files, but more to use 
some perl basic instruccions to get a 
small objective. simple, usefull, for 
the begginer. thanks for the knowledge 
anyways. 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Perl Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.