Perl使用chdir

代码如下

use strict;
use warnings;

# 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();

1;

==

posted on 2012-02-13 11:11  perlman  阅读(3987)  评论(0编辑  收藏  举报

导航