ZHAO, BING wrote:
> Hi,
> first, I want to thank all who viewed my first question days
> before, especially to those who took time to answer it. It was
> trenmendous encouragement for a beginner perlee like me. Thanks again.
> My question:
> Is there a way to call or maybe get the # of files in a
> directory?
> I am trying to build a storage directory for files which
> automatically empits itself when the # files reaches 50. If there is
> some commands which do that(like whatever COMMAND(directory) ), the
> problem would be solved, I then will be OK to program the rest of perl.
> To be more specific, I have a CGI online page which takes
> uploaded files(press 'upload' on my website, then upload whatever text
> files, uaually DNA sequence files) then I need to modify the files a bit
> then save the files to the STORAGE directory, the directory can't be
> infinitely increasing, so I need to empty it when the time comes. And I
> need to keep track of the # of files in that 'damn' directory.
> Maybe you got better idea about how to store the files to
> the directory? Let me know then.
>
perldoc -f opendir
perldoc -f readdir
perldoc -f closedir
perldoc -f unlink
This should get you started. You can also look into file globs though I
have never preferred them, for whatever reason.
perldoc -f stat
perldoc -f sort
Might also come in handy as presumably you want to remove the oldest,
highest number, etc.
-- UNTESTED --
opendir my $DIRHANDLE, '/path/to/dir' or die "Can't get directory
handle: $!";
my @filelist = grep { $_ ne '.' and $_ ne '..' } readdir $DIRHANDLE;
closedir $DIRHANDLE;
if (@filelist > 50) {
for my $index (50 .. @filelist) {
unlink $filelist[$index] or die "Can't remove file
$filelist[$index]: $!";
}
}
> Thank you all for reading my 'junk'.
>
HTH,
http://danconia.org
> best,
>
> Bing
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>