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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Files Question

Status
Not open for further replies.

Neoport

Programmer
Aug 4, 2000
10
US
Hi,

I have a folder with 800 files, and I was wondering if there's a way I can copy the name of each file into a text file so I can work with the text file instead.

Thanks
 
you can open directories just like you can open files.

$dirname = "/tmp";

opendir(DIR, $dirname);
@files = readdir(DIR);
closedir(DIR);

now @files has the contents of your directory. you may want to print it before you do anything with it, because i don't remember if the firest two elements are . and .. or not.
 
yeah it will capture . and .. I usually do this to read a directory and put it in alphabetical order

while (defined ($file = readdir(DIR)))
{
next if $file =~ /^\.\.?$/; #I got this from the cookbook.
push(@file, $file);
@file = sort(@file);
}

Just remember @file and $file are different change the name if you get confused.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top