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!

Get a file list, put into array?

Status
Not open for further replies.

Numbski

MIS
Mar 27, 2001
56
0
0
US
Seems like a simple enough task....completely in PERL code, I need to get a listing off all files in a directory, and enter them into an array to be worked on. Each array entry has ONLY the file name. No spaces, no newlines, no attribs. Just *.*, and nothing more (all files will be in 8.3 format). For extra credit, a routing that will run through every file in that array, and rename them to lowercase. To rename, you would do a

use File::Copy;

then

copy (PaCmAn.ZiP,pacman.zip);

So....any takers?
 
[tt]
opendir DIR, "/what/ever/";
my @array = readdir DIR;
closedir DIR;[/tt]


ta da! "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Um....do I need to do:

foreach $file(@array) {
$file=chomp($file);
}

or is it going to be nice and clean the way you suggested?
 
Oops! I still need a foreach statement that will drop all alpha chars to lower case.... :)
 
the array will contain only file names, no spaces, etc.
to lower everything:[tt]
@array = map {lc} @array;
[/tt]
"If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top