Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 |
2 | .\" | |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
5 | .de Sh \" Subsection heading | |
6 | .br | |
7 | .if t .Sp | |
8 | .ne 5 | |
9 | .PP | |
10 | \fB\\$1\fR | |
11 | .PP | |
12 | .. | |
13 | .de Sp \" Vertical space (when we can't use .PP) | |
14 | .if t .sp .5v | |
15 | .if n .sp | |
16 | .. | |
17 | .de Vb \" Begin verbatim text | |
18 | .ft CW | |
19 | .nf | |
20 | .ne \\$1 | |
21 | .. | |
22 | .de Ve \" End verbatim text | |
23 | .ft R | |
24 | .fi | |
25 | .. | |
26 | .\" Set up some character translations and predefined strings. \*(-- will | |
27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
28 | .\" double quote, and \*(R" will give a right double quote. | will give a | |
29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to | |
30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' | |
31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. | |
32 | .tr \(*W-|\(bv\*(Tr | |
33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' | |
34 | .ie n \{\ | |
35 | . ds -- \(*W- | |
36 | . ds PI pi | |
37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
39 | . ds L" "" | |
40 | . ds R" "" | |
41 | . ds C` "" | |
42 | . ds C' "" | |
43 | 'br\} | |
44 | .el\{\ | |
45 | . ds -- \|\(em\| | |
46 | . ds PI \(*p | |
47 | . ds L" `` | |
48 | . ds R" '' | |
49 | 'br\} | |
50 | .\" | |
51 | .\" If the F register is turned on, we'll generate index entries on stderr for | |
52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | |
53 | .\" entries marked with X<> in POD. Of course, you'll have to process the | |
54 | .\" output yourself in some meaningful fashion. | |
55 | .if \nF \{\ | |
56 | . de IX | |
57 | . tm Index:\\$1\t\\n%\t"\\$2" | |
58 | .. | |
59 | . nr % 0 | |
60 | . rr F | |
61 | .\} | |
62 | .\" | |
63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes | |
64 | .\" way too many mistakes in technical documents. | |
65 | .hy 0 | |
66 | .if n .na | |
67 | .\" | |
68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). | |
69 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
70 | . \" fudge factors for nroff and troff | |
71 | .if n \{\ | |
72 | . ds #H 0 | |
73 | . ds #V .8m | |
74 | . ds #F .3m | |
75 | . ds #[ \f1 | |
76 | . ds #] \fP | |
77 | .\} | |
78 | .if t \{\ | |
79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) | |
80 | . ds #V .6m | |
81 | . ds #F 0 | |
82 | . ds #[ \& | |
83 | . ds #] \& | |
84 | .\} | |
85 | . \" simple accents for nroff and troff | |
86 | .if n \{\ | |
87 | . ds ' \& | |
88 | . ds ` \& | |
89 | . ds ^ \& | |
90 | . ds , \& | |
91 | . ds ~ ~ | |
92 | . ds / | |
93 | .\} | |
94 | .if t \{\ | |
95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" | |
96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
101 | .\} | |
102 | . \" troff and (daisy-wheel) nroff accents | |
103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' | |
104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
110 | .ds ae a\h'-(\w'a'u*4/10)'e | |
111 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
112 | . \" corrections for vroff | |
113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' | |
114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
115 | . \" for low resolution devices (crt and lpr) | |
116 | .if \n(.H>23 .if \n(.V>19 \ | |
117 | \{\ | |
118 | . ds : e | |
119 | . ds 8 ss | |
120 | . ds o a | |
121 | . ds d- d\h'-1'\(ga | |
122 | . ds D- D\h'-1'\(hy | |
123 | . ds th \o'bp' | |
124 | . ds Th \o'LP' | |
125 | . ds ae ae | |
126 | . ds Ae AE | |
127 | .\} | |
128 | .rm #[ #] #H #V #F C | |
129 | .\" ======================================================================== | |
130 | .\" | |
131 | .IX Title "File::Basename 3" | |
132 | .TH File::Basename 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide" | |
133 | .SH "NAME" | |
134 | File::Basename \- Parse file paths into directory, filename and suffix. | |
135 | .SH "SYNOPSIS" | |
136 | .IX Header "SYNOPSIS" | |
137 | .Vb 1 | |
138 | \& use File::Basename; | |
139 | .Ve | |
140 | .PP | |
141 | .Vb 2 | |
142 | \& ($name,$path,$suffix) = fileparse($fullname,@suffixlist); | |
143 | \& $name = fileparse($fullname,@suffixlist); | |
144 | .Ve | |
145 | .PP | |
146 | .Vb 2 | |
147 | \& $basename = basename($fullname,@suffixlist); | |
148 | \& $dirname = dirname($fullname); | |
149 | .Ve | |
150 | .SH "DESCRIPTION" | |
151 | .IX Header "DESCRIPTION" | |
152 | These routines allow you to parse file paths into their directory, filename | |
153 | and suffix. | |
154 | .PP | |
155 | \&\fB\s-1NOTE\s0\fR: \f(CW\*(C`dirname()\*(C'\fR and \f(CW\*(C`basename()\*(C'\fR emulate the behaviours, and | |
156 | quirks, of the shell and C functions of the same name. See each | |
157 | function's documentation for details. If your concern is just parsing | |
158 | paths it is safer to use File::Spec's \f(CW\*(C`splitpath()\*(C'\fR and | |
159 | \&\f(CW\*(C`splitdir()\*(C'\fR methods. | |
160 | .PP | |
161 | It is guaranteed that | |
162 | .PP | |
163 | .Vb 2 | |
164 | \& # Where $path_separator is / for Unix, \e for Windows, etc... | |
165 | \& dirname($path) . $path_separator . basename($path); | |
166 | .Ve | |
167 | .PP | |
168 | is equivalent to the original path for all systems but \s-1VMS\s0. | |
169 | .ie n .IP """fileparse""" 4 | |
170 | .el .IP "\f(CWfileparse\fR" 4 | |
171 | .IX Item "fileparse" | |
172 | .Vb 3 | |
173 | \& my($filename, $directories, $suffix) = fileparse($path); | |
174 | \& my($filename, $directories, $suffix) = fileparse($path, @suffixes); | |
175 | \& my $filename = fileparse($path, @suffixes); | |
176 | .Ve | |
177 | .Sp | |
178 | The \f(CW\*(C`fileparse()\*(C'\fR routine divides a file path into its \f(CW$directories\fR, \f(CW$filename\fR | |
179 | and (optionally) the filename \f(CW$suffix\fR. | |
180 | .Sp | |
181 | $directories contains everything up to and including the last | |
182 | directory separator in the \f(CW$path\fR including the volume (if applicable). | |
183 | The remainder of the \f(CW$path\fR is the \f(CW$filename\fR. | |
184 | .Sp | |
185 | .Vb 2 | |
186 | \& # On Unix returns ("baz", "/foo/bar/", "") | |
187 | \& fileparse("/foo/bar/baz"); | |
188 | .Ve | |
189 | .Sp | |
190 | .Vb 2 | |
191 | \& # On Windows returns ("baz", "C:\efoo\ebar\e", "") | |
192 | \& fileparse("C:\efoo\ebar\ebaz"); | |
193 | .Ve | |
194 | .Sp | |
195 | .Vb 2 | |
196 | \& # On Unix returns ("", "/foo/bar/baz/", "") | |
197 | \& fileparse("/foo/bar/baz/"); | |
198 | .Ve | |
199 | .Sp | |
200 | If \f(CW@suffixes\fR are given each element is a pattern (either a string or a | |
201 | \&\f(CW\*(C`qr//\*(C'\fR) matched against the end of the \f(CW$filename\fR. The matching | |
202 | portion is removed and becomes the \f(CW$suffix\fR. | |
203 | .Sp | |
204 | .Vb 2 | |
205 | \& # On Unix returns ("baz", "/foo/bar", ".txt") | |
206 | \& fileparse("/foo/bar/baz", qr/\e.[^.]*/); | |
207 | .Ve | |
208 | .Sp | |
209 | If type is non-Unix (see \f(CW\*(C`fileparse_set_fstype()\*(C'\fR) then the pattern | |
210 | matching for suffix removal is performed case\-insensitively, since | |
211 | those systems are not case-sensitive when opening existing files. | |
212 | .Sp | |
213 | You are guaranteed that \f(CW\*(C`$directories . $filename . $suffix\*(C'\fR will | |
214 | denote the same location as the original \f(CW$path\fR. | |
215 | .ie n .IP """basename""" 4 | |
216 | .el .IP "\f(CWbasename\fR" 4 | |
217 | .IX Item "basename" | |
218 | .Vb 2 | |
219 | \& my $filename = basename($path); | |
220 | \& my $filename = basename($path, @suffixes); | |
221 | .Ve | |
222 | .Sp | |
223 | This function is provided for compatibility with the Unix shell command | |
224 | \&\f(CWbasename(1)\fR. It does \fB\s-1NOT\s0\fR always return the file name portion of a | |
225 | path as you might expect. To be safe, if you want the file name portion of | |
226 | a path use \f(CW\*(C`fileparse()\*(C'\fR. | |
227 | .Sp | |
228 | \&\f(CW\*(C`basename()\*(C'\fR returns the last level of a filepath even if the last | |
229 | level is clearly directory. In effect, it is acting like \f(CW\*(C`pop()\*(C'\fR for | |
230 | paths. This differs from \f(CW\*(C`fileparse()\*(C'\fR's behaviour. | |
231 | .Sp | |
232 | .Vb 3 | |
233 | \& # Both return "bar" | |
234 | \& basename("/foo/bar"); | |
235 | \& basename("/foo/bar/"); | |
236 | .Ve | |
237 | .Sp | |
238 | @suffixes work as in \f(CW\*(C`fileparse()\*(C'\fR except all regex metacharacters are | |
239 | quoted. | |
240 | .Sp | |
241 | .Vb 3 | |
242 | \& # These two function calls are equivalent. | |
243 | \& my $filename = basename("/foo/bar/baz.txt", ".txt"); | |
244 | \& my $filename = fileparse("/foo/bar/baz.txt", qr/\eQ.txt\eE/); | |
245 | .Ve | |
246 | .Sp | |
247 | Also note that in order to be compatible with the shell command, | |
248 | \&\f(CW\*(C`basename()\*(C'\fR does not strip off a suffix if it is identical to the | |
249 | remaining characters in the filename. | |
250 | .ie n .IP """dirname""" 4 | |
251 | .el .IP "\f(CWdirname\fR" 4 | |
252 | .IX Item "dirname" | |
253 | This function is provided for compatibility with the Unix shell | |
254 | command \f(CWdirname(1)\fR and has inherited some of its quirks. In spite of | |
255 | its name it does \fB\s-1NOT\s0\fR always return the directory name as you might | |
256 | expect. To be safe, if you want the directory name of a path use | |
257 | \&\f(CW\*(C`fileparse()\*(C'\fR. | |
258 | .Sp | |
259 | Only on \s-1VMS\s0 (where there is no ambiguity between the file and directory | |
260 | portions of a path) and AmigaOS (possibly due to an implementation quirk in | |
261 | this module) does \f(CW\*(C`dirname()\*(C'\fR work like \f(CW\*(C`fileparse($path)\*(C'\fR, returning just the | |
262 | \&\f(CW$directories\fR. | |
263 | .Sp | |
264 | .Vb 2 | |
265 | \& # On VMS and AmigaOS | |
266 | \& my $directories = dirname($path); | |
267 | .Ve | |
268 | .Sp | |
269 | When using Unix or \s-1MSDOS\s0 syntax this emulates the \f(CWdirname(1)\fR shell function | |
270 | which is subtly different from how \f(CW\*(C`fileparse()\*(C'\fR works. It returns all but | |
271 | the last level of a file path even if the last level is clearly a directory. | |
272 | In effect, it is not returning the directory portion but simply the path one | |
273 | level up acting like \f(CW\*(C`chop()\*(C'\fR for file paths. | |
274 | .Sp | |
275 | Also unlike \f(CW\*(C`fileparse()\*(C'\fR, \f(CW\*(C`dirname()\*(C'\fR does not include a trailing slash on | |
276 | its returned path. | |
277 | .Sp | |
278 | .Vb 2 | |
279 | \& # returns /foo/bar. fileparse() would return /foo/bar/ | |
280 | \& dirname("/foo/bar/baz"); | |
281 | .Ve | |
282 | .Sp | |
283 | .Vb 3 | |
284 | \& # also returns /foo/bar despite the fact that baz is clearly a | |
285 | \& # directory. fileparse() would return /foo/bar/baz/ | |
286 | \& dirname("/foo/bar/baz/"); | |
287 | .Ve | |
288 | .Sp | |
289 | .Vb 2 | |
290 | \& # returns '.'. fileparse() would return 'foo/' | |
291 | \& dirname("foo/"); | |
292 | .Ve | |
293 | .Sp | |
294 | Under \s-1VMS\s0, if there is no directory information in the \f(CW$path\fR, then the | |
295 | current default device and directory is used. | |
296 | .ie n .IP """fileparse_set_fstype""" 4 | |
297 | .el .IP "\f(CWfileparse_set_fstype\fR" 4 | |
298 | .IX Item "fileparse_set_fstype" | |
299 | .Vb 2 | |
300 | \& my $type = fileparse_set_fstype(); | |
301 | \& my $previous_type = fileparse_set_fstype($type); | |
302 | .Ve | |
303 | .Sp | |
304 | Normally File::Basename will assume a file path type native to your current | |
305 | operating system (ie. /foo/bar style on Unix, \efoo\ebar on Windows, etc...). | |
306 | With this function you can override that assumption. | |
307 | .Sp | |
308 | Valid \f(CW$types\fR are \*(L"MacOS\*(R", \*(L"\s-1VMS\s0\*(R", \*(L"AmigaOS\*(R", \*(L"\s-1OS2\s0\*(R", \*(L"\s-1RISCOS\s0\*(R", | |
309 | \&\*(L"MSWin32\*(R", \*(L"\s-1DOS\s0\*(R" (also \*(L"\s-1MSDOS\s0\*(R" for backwards bug compatibility), | |
310 | \&\*(L"Epoc\*(R" and \*(L"Unix\*(R" (all case\-insensitive). If an unrecognized \f(CW$type\fR is | |
311 | given \*(L"Unix\*(R" will be assumed. | |
312 | .Sp | |
313 | If you've selected \s-1VMS\s0 syntax, and the file specification you pass to | |
314 | one of these routines contains a \*(L"/\*(R", they assume you are using Unix | |
315 | emulation and apply the Unix syntax rules instead, for that function | |
316 | call only. | |
317 | .SH "SEE ALSO" | |
318 | .IX Header "SEE ALSO" | |
319 | \&\fIdirname\fR\|(1), \fIbasename\fR\|(1), File::Spec |