how to move the directory contents into an Array in Perl?
I need to open a directory, read the contents/files in the directory and I've to move all those files in the directory into an array.
I have to do all these things using a Perl Script. Can anyone please give me the code to move the directory contents into an array?
PLEASE FILL THE FOLLOWING SCRIPT:
opendir(INFILE_DIR,"$Input_Path") || die "cannot open $Input_Path ";
my @files =---------------;
What will come at t开发者_JAVA百科he "------" area to move the directory contents into an array.
Thanks in advance.
This will not require you to chdir
to the wanted directory:
opendir my $dh, $dir or die "Cannot open directory $dir\n";
my @files = readdir $dh;
closedir $dh;
chdir $dir or die "Can't cd to $dir: $!\n";
my @contents = glob("*");
After opening a directory you have to read it (readdir) in order to get the files.
opendir(my $dh, ".");
my @files=readdir($dh);
closedir $dh;
The function you are looking for is readdir
. You can find more help about using it by doing a perldoc -f readdir
.
精彩评论