Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

limits to opendir and readdir

Status
Not open for further replies.

rotis23

Programmer
Aug 29, 2002
121
GB
Hi All,

I've got a program that has to trawl through a directory with many (I MEAN many) files - it's a maildir of about 6GB on an NFS mount on a solaris 8 box.

What are the limits with opendir and readdir in this context? I'm trawling thorugh it deleting files older than a couple of weeks.

The process takes a large amount of time and using top it seems to be in a sleep state - is it just reading the directory?

Any advice? Is this better written in C?

Thanks for your help, rotis23
 
opendir, shouldn't be a limit
readdir, only limited by available memory one would have thought

Have you tried printing a debug log to see how asleep it actually is?

--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Thanks Paul - it's working, just taking a long time.

 
There may be better options using 'globbing'
File::Find might also be an option

Dunno if it'll speed it up though, it's proabably still based on the type of building blocks, but it might be worth a gander at any rate

G'Luck
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
If you're using readdir in scalar context, available memory shouldn't be an issue. In list context, it'll return a list of all the files in the directory, which (if there are lots of files), will eat up a huge amount of memory - here's an example of that (code untested):
Code:
unlink for grep { -M > 14 } readdir DIR;

In scalar context, readdir just returns the next file in the directory, so there should only be one filename in memory at a time, for example:
Code:
while (my $file = readdir DIR) {
   unlink $file if -M $file > 14;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top