0

for example i have :
file directory: C:\Users\Desktop\program
files in directory: cheese(folder) ,veggie(txt file), meat(doc file)
How do i record down the names of the files and folder in the directory? Thanks in advance!!

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • 1
    You forgot to include your code so far and details of exactly where you are having problems. – Mark Parnell Apr 19 '13 at 02:59
  • 1
    See the following: [How do I read in the contents of a directory in Perl?](http://stackoverflow.com/questions/22566/how-do-i-read-in-the-contents-of-a-directory-in-perl) – Kenosis Apr 19 '13 at 04:13

2 Answers2

1

Another way is to use glob:

my @files = <*>;

This will give you all of the files in the current directory.

This method is convenient if you only want to find certain files:

my @jpegs = <*.jpg>;

If that isn't the directory you want, change to the current directory or include the path:

my @files = </foo/bar*>;

Note that you should use forward slashes even if doing this on Windows.

0

Try the following:

opendir FOLDER, $folder or die "Cant open folder $folder: $!";
my @file= readdir FOLDER;
closedir FOLDER;
ahjohnston25
  • 1,915
  • 15
  • 36