我有一条路径:/path/to/here/file.txt。
我想让/path/to/
使用
my ($file, $dir) = fileparse($fullPath);我可以让file.txt和/path/to/here/
如何只获取/path/to/
发布于 2017-08-05 04:00:21
use Path::Class qw( file );
say file("/path/to/here/file.txt")->dir->parent;请注意,这不会执行任何文件系统检查,因此即使/path/to是一个符号链接,它也会返回/path/to,因此不是真正的父目录。
发布于 2017-08-05 04:06:58
$ perl -MPath::Tiny -e 'CORE::say path($ARGV[0])->parent->parent' /path/to/here/file.txt这也不会执行任何文件系统检查。只使用File::Spec做这件事往往会变得单调乏味。我不能肯定下面的作品:
$ perl -MFile::Spec::Functions=splitpath,catpath,catdir,splitdir -e \
'($v, $d) = splitpath($ARGV[0]); @d = splitdir $d; splice @d, -2; \
CORE::say catpath($v, catdir (@d))' /path/to/here/file.txthttps://stackoverflow.com/questions/45514482
复制相似问题