时间:2021-03-06 10:13:30 | 栏目:perl | 点击:次
# Print all files in a directory
sub print_files {
my $dir = 'd:/code';
opendir DIR, $dir or die $!;
my @files = readdir DIR;
chdir $dir; # Use chdir or -f will not work, since -f need absolutely path
foreach my $file (@files) {
if (-f $file) {
print "$file\n";
}
}
closedir DIR;
}
&print_files();