-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
190 lines (122 loc) · 6.03 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
NAME
File::Basename::Extra - Extension to File::Basename, adds named access
to file parts and handling of filename suffixes
VERSION
version 0.004
SYNOPSIS
# Note: by default no symbols get exported so make sure you export
# the ones you need!
use File::Basename::Extra qw(basename);
# basename and friends
my $file = basename('/foo/bar/file.txt'); # "file.txt"
my $fileext = basename_suffix('/foo/bar/file.txt'); # ".txt"
my $filenoext = basename_nosuffix('/foo/bar/file.txt'); # "file"
# dirname
my $dir = dirname('/foo/bar/file.txt'); # "/foo/bar/"
# fileparse
my ($filename, $dirs, $suffix) = fileparse('/foo/bar/file.txt', qr/\.[^.]*/);
# ("file", "/foo/bar/", ".txt")
# pathname
my $path = pathname('/foo/bar/file.txt'); # "/foo/bar/"
# fullname and friends
my $full = fullname('/foo/bar/file.txt'); # "/foo/bar/file.txt"
my $fullext = fullname_suffix('/foo/bar/file.txt'); # ".txt"
my $fullnoext = fullname_nosuffix('/foo/bar/file.txt'); # "/foo/bar/file"
# getting/setting the default suffix patterns
my @patterns = default_suffix_patterns(); # Returns the currently active patterns
# setting the default suffix patterns
my @previous = default_suffix_patterns(qr/[._]bar/, '\.baz');
# Now only .bar, _bar, and .baz are matched suffixes
DESCRIPTION
This module provides functionalty for handling file name suffixes (aka
file name extensions).
FUNCTIONS
fileparse FILEPATH
fileparse FILEPATH PATTERN_LIST
basename FILEPATH
basename FILEPATH PATTERN_LIST
dirname FILEPATH
fileparse_set_fstype FSTYPE
These functions are exactly the same as the corresponding ones from
File::Basename except that they aren't exported by default.
basename_suffix FILEPATH
basename_suffix FILEPATH PATTERN_LIST
Returns the file name suffix part of the given filepath. The default
suffix patterns are used if none are provided. Behaves the same as
basename, i.e., it uses the last last level of a filepath as filename,
even if the last level is clearly directory.
Also, like basename, files that consist of only a matched suffix are
treated as if they do not have a suffix. So, using the default suffix
pattern, basename_suffix('/Users/home/.profile') would return an empty
string.
Note: Like the original basename function from File::Basename, suffix
patterns are automatically escaped so pattern .bar only matches .bar
and not e.g., _bar (this is not done for the default suffix patterns,
nor for patterns provided to the non-basename family functions of this
module!).
basename_nosuffix FILEPATH
basename_nosuffix FILEPATH PATTERN_LIST
Acts basically the same as the original basename function, except that
the default suffix patterns are used to strip the name of its suffixes
when none are provided.
Also, like basename, files that consist of only a matched suffix are
treated as if they do not have a suffix. So, using the default suffix
pattern, basename_nosuffix('/Users/home/.profile') would return
.profile.
Note: Like the original basename function from File::Basename, suffix
patterns are automatically escaped so pattern .bar only matches .bar
and not e.g., _bar (this is not done for the default suffix patterns,
nor for patterns provided to the non-basename family of functions of
this module!).
filename FILEPATH
filename FILEPATH PATTERN_LIST
Returns just the filename of the filepath, optionally stripping the
suffix when it matches a provided suffix patterns. Basically the same
as calling fileparse in scalar context.
filename_suffix FILEPATH
filename_suffix FILEPATH PATTERN_LIST
Returns the matched suffix of the filename. The default suffix patterns
are used when none are provided.
filename_nosuffix FILEPATH
filename_nosuffix FILEPATH PATTERN_LIST
Returns the filename with the the matched suffix stripped. The default
suffix patterns are used when none are provided.
pathname FILEPATH
Returns the path part of the file. Contrary to dirname, a filepath that
is clearly a directory, is treated as such (e.g., on Unix,
pathname('/foo/bar/') returns /foo/bar/).
fullname FILEPATH
fullname FILEPATH PATTERN_LIST
Returns the provided filepath, optionally stripping the filename of its
matching suffix.
fullname_suffix FILEPATH
fullname_suffix FILEPATH PATTERN_LIST
Synonym for filename_suffix.
fullname_nosuffix FILEPATH
fullname_nosuffix FILEPATH PATTERN_LIST
Returns the full filepath with the the matched suffix stripped. The
default suffix patterns are used when none are provided.
default_suffix_patterns
default_suffix_patterns NEW_PATTERN_LIST
The default suffix pattern list (see the fileparse function in
File::Basename for details) is qr/\.[^.]*/. Meaning that this defines
the suffix as the part of the filename from (and including) the last
dot. In other words, the part of a filename that is popularly known as
the file extension.
You can alter the suffix matching by proving this function with a
different pattern list.
This function returns the pattern list that was effective before
optionally changing it.
BUGS
Please report any bugs or feature requests on the bugtracker website
<https://github.com/HayoBaan/File-Basename-Extra/issues>.
When submitting a bug or request, please include a test-file or a patch
to an existing test-file that illustrates the bug or desired feature.
SEE ALSO
File::Basename for the suffix matching and platform specific details.
AUTHOR
Hayo Baan <[email protected]>
COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by Hayo Baan.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.