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!!
Asked
Active
Viewed 81 times
0

Jonathan Hall
- 75,165
- 16
- 143
- 189
-
1You forgot to include your code so far and details of exactly where you are having problems. – Mark Parnell Apr 19 '13 at 02:59
-
1See 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 Answers
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
-
-
@user2297543 another question - another question ;) and no, don't do that, only look at [perldoc](http://perldoc.perl.org/functions/open.html) – gaussblurinc Apr 19 '13 at 04:12