Re: Perl Question Recap
thanks for all the inputs !!!
I ended up using the rmtree command...
I needed to execute this in Perl....
because I have a web based emailer written in Perl...
One part of the program will create an upload directory for the
user ... however... I couldn't get a quota on it.... so I just delete
the directory and re-create it when they log in..... thus....
they can't upload a million files and take up hard disk space...
(well, I suppose they could for one session...)
Anyway... I'm really new to Perl.... and I'm guessing that
I can't run shell commands within a perl script...
thanks
Mike
The following message was sent by Hamma Scott <scott_hamma@yahoo.com> on Wed, 18 Jul 2001 04:41:29 -0700 (PDT).
> Mike's Question:
>
> I want to delete a directory that will have files in
> it...I don't know the name of the files.... there for
> wildcards might be needed....
>
> I understand that "rmdir" will wipe out an empty
> directory....and "unlink" will wipe out files (only if
>
> I know the names of the files)
>
> What would be a nice command to remove a dirtory that
> had files in it? Even better.... what would be a nice
> command to delete all files in one directory...
> (leaving the directory intact)
> -------------------------------------------------------From
> Lamer:
>
> Simply Speaking, This would have been done better with
>
> these shell commands:
>
> # cd /directory
> # rm -rf *
> # cd ..;
> -------------------------------------------------------
> >From Joost:
>
> #!/usr/bin/perl -w
> use File::Path;
> rmtree("some/dir", 0, 1);
>
> =pod
> man File::Path
> =cut
> -------------------------------------------------------From
> Craig:
>
> to remove a dirtory that had files in it:
>
> - rm -rf directory
>
> to delete all files in one directory
> (leaving the directory intact)
>
> - rm -rf directory/*
>
> to delete everything in a directory, including
> subdirectories
>
> - find . -type f | xargs rm -f
>
> to delete all files in a directory or its
> subdirectories,
> but keep the directory structure intact.
>
> Perl isn't required.
>
> -------------------------------------------------------From
> Bud:
>
> >Even better.... what would be a nice command to
> delete all filesin one directory... (leaving the
> directory intact)
>
> #! /usr/bin/perl -w
>
> $dir = "/path/to/dir";
>
> opendir(DIR, $dir) or die "can't opendir $dir: $!";
>
> while ( defined ($file = readdir DIR) ) {
> next if $file =~ /^\.\.?$/; # skip . and ..
> unlink $file;
> }
>
> Quick and dirty, but I think it will delete all files
> in one directory. Won't handle subdirs. Then you
> could probably just
>
> close(DIR);
> rmdir $dir;
>
> to get rid of the directory.
>
> -------------------------------------------------------
> >From Larry Wall:
> "There's more than one way to do things"
>
> A fine example of life imitating art ;-)
>
> Scott Hamma
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/
>
>
> --
> To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
>
>
Reply to: