我试图从当前工作目录移回一级,但没有成功。
use strict;
use warnings;
use Cwd qw();
my $path = Cwd::cwd();
print "Debug : $pathn";
从上面的代码,我可以得到当前的工作目录,但需要回到下一级。
实验:当前工作目录= 'C:/abc/tmp/folder'所需目录= 'C:/abc/tmp'
您不需要任何模块来更改当前工作目录。
chdir '..';
可以满足您的需要。
chdir
是一个内置操作符,所以不需要安装任何操作符
我不确定Perl chdir()函数是否接受".."参数。如果它你可以这样做:
chdir("..");
上一个目录。
如果没有,你将不得不做一些事情,如:
$currdir = `pwd`; chomp $currdir; # gets current directory
$currdir =~ s/ /[^/]+$//; # removes the last / and everything after it
chdir($currdir);
查看File::Basename。检查'fileparse()'或'dirname()'方法
你实际上需要尝试进入上层目录,即使用..
某处…
#!/usr/bin/perl -w
use strict;
use Cwd 'abs_path';
my $path = Cwd::cwd();
print abs_path($path . '/..');