- use File::Basename
-
my $file = "/usr/bin/perl";
-
my $basename = basename $file;
-
my $dirname = dirname $file;
-
-
print "$basename, $dirname";
-
-
#perl, /usr/bin
fileparse
- $filepath = /home/test/my.pl
- my ($filename, $filedir, $subffix) = fileparse($filepath, qr/\.[^.]*/);
-
my $name = fileparse($filepath);
-
print $filename, $filedir, $subffix, "\n"; #will be my, /home/test/ .pl
- print $name; #my.pl
You are guaranteed that "$directories . $filename . $suffix" will denote the same location as the original $path.
the $subffix is the optional if you put a string or pattern, may get $subffix.
fileparse_set_fstype
- my $type = fileparse_set_fstype();
- my $previous_type = fileparse_set_fstype($type);
Valid $types are "MacOS", "VMS", "AmigaOS", "OS2", "RISCOS",
"MSWin32", "DOS" (also "MSDOS" for backwards bug compatibility),
"Epoc" and "Unix" (all case-insensitive). If an unrecognized $type
is given "Unix" will be assumed.
阅读(706) | 评论(0) | 转发(0) |