James Kipp wrote: > > Im now trying to list a directory, but only the files in that > > directory that > > finish with a perticular ending, say .html, i.e *.html. Ive > > got this far, > > but having troubles, wondering if you could have a look for me: > >
I guess this was mailed off-list? Thanks for copying it back to us. > you are pretty close, try the following > > use strict; > use warnings; > > $dir = '/staff/lad/public_html/SWT'; > > opendir(DIR, $dir) or die "Cannot open directory"; > # read the dir contents into a list, and grep out the . and .. dir entries > @entries = grep (!/^\.\.?$/ , readdir (DIR)); > closedir(DIR); > foreach (@entries) > { > print "$_\n" if /.*\.html$/; > } > > --- > Note, this does not deal with iterating through the subdirs of this > directory, for that you would have to write a recursion routine OR use > File::Find which does all that and more for you. In fact many would say to > use File::Find for any job like this. Do a google search for it and you will > find plenty of examples, scripts, and documentation for it I would be one of those who would say 'use File::Find for any job like this'! Although it is a little quirky with its callback interface, it's fine for simply listing directories. As for documentation, perldoc FIle::Find is OK for the basic stuff (I believe it's a standard module). The simple directory listing above could be achieved with just print "$_\n" foreach glob '/staff/lad/public_html/SWT/*.html'; although if it is an assigment, as I believe it is, then this could be considered a little cheeky! Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]