| 1 |
'\" |
| 2 |
'\" Copyright (c) 1995-1996 Sun Microsystems, Inc. |
| 3 |
'\" |
| 4 |
'\" See the file "license.terms" for information on usage and redistribution |
| 5 |
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 6 |
'\" |
| 7 |
.TH filename n 7.5 Tcl "Tcl Built-In Commands" |
| 8 |
.so man.macros |
| 9 |
.BS |
| 10 |
'\" Note: do not modify the .SH NAME line immediately below! |
| 11 |
.SH NAME |
| 12 |
filename \- File name conventions supported by Tcl commands |
| 13 |
.BE |
| 14 |
.SH INTRODUCTION |
| 15 |
.PP |
| 16 |
All Tcl commands and C procedures that take file names as arguments |
| 17 |
expect the file names to be in one of three forms, depending on the |
| 18 |
current platform. On each platform, Tcl supports file names in the |
| 19 |
standard forms(s) for that platform. In addition, on all platforms, |
| 20 |
Tcl supports a Unix-like syntax intended to provide a convenient way |
| 21 |
of constructing simple file names. However, scripts that are intended |
| 22 |
to be portable should not assume a particular form for file names. |
| 23 |
Instead, portable scripts must use the \fBfile split\fR and \fBfile |
| 24 |
join\fR commands to manipulate file names (see the \fBfile\fR manual |
| 25 |
entry for more details). |
| 26 |
.SH "PATH TYPES" |
| 27 |
.PP |
| 28 |
File names are grouped into three general types based on the starting point |
| 29 |
for the path used to specify the file: absolute, relative, and |
| 30 |
volume-relative. Absolute names are completely qualified, giving a path to |
| 31 |
the file relative to a particular volume and the root directory on that |
| 32 |
volume. Relative names are unqualified, giving a path to the file relative |
| 33 |
to the current working directory. Volume-relative names are partially |
| 34 |
qualified, either giving the path relative to the root directory on the |
| 35 |
current volume, or relative to the current directory of the specified |
| 36 |
volume. The \fBfile pathtype\fR command can be used to determine the |
| 37 |
type of a given path. |
| 38 |
.SH "PATH SYNTAX" |
| 39 |
.PP |
| 40 |
The rules for native names depend on the value reported in the Tcl |
| 41 |
\fBplatform\fR element of the \fBtcl_platform\fR array: |
| 42 |
.TP 10 |
| 43 |
\fBUnix\fR |
| 44 |
. |
| 45 |
On Unix and Apple macOS platforms, Tcl uses path names where the |
| 46 |
components are separated by slashes. Path names may be relative or |
| 47 |
absolute, and file names may contain any character other than slash. |
| 48 |
The file names \fB\&.\fR and \fB\&..\fR are special and refer to the |
| 49 |
current directory and the parent of the current directory respectively. |
| 50 |
Multiple adjacent slash characters are interpreted as a single |
| 51 |
separator, except for the first double slash \fB//\fR in absolute paths. |
| 52 |
Any number of trailing slash characters at the end of a |
| 53 |
path are simply ignored, so the paths \fBfoo\fR, \fBfoo/\fR and |
| 54 |
\fBfoo//\fR are all identical, and in particular \fBfoo/\fR does not |
| 55 |
necessarily mean a directory is being referred. |
| 56 |
.RS |
| 57 |
.PP |
| 58 |
The following examples illustrate various forms of path |
| 59 |
names: |
| 60 |
.TP 15 |
| 61 |
\fB/\fR |
| 62 |
. |
| 63 |
Absolute path to the root directory. |
| 64 |
.TP 15 |
| 65 |
\fB/etc/passwd\fR |
| 66 |
. |
| 67 |
Absolute path to the file named \fBpasswd\fR in the directory |
| 68 |
\fBetc\fR in the root directory. |
| 69 |
.TP 15 |
| 70 |
\fB\&.\fR |
| 71 |
. |
| 72 |
Relative path to the current directory. |
| 73 |
.TP 15 |
| 74 |
\fBfoo\fR |
| 75 |
. |
| 76 |
Relative path to the file \fBfoo\fR in the current directory. |
| 77 |
.TP 15 |
| 78 |
\fBfoo/bar\fR |
| 79 |
. |
| 80 |
Relative path to the file \fBbar\fR in the directory \fBfoo\fR in the |
| 81 |
current directory. |
| 82 |
.TP 15 |
| 83 |
\fB\&../foo\fR |
| 84 |
. |
| 85 |
Relative path to the file \fBfoo\fR in the directory above the current |
| 86 |
directory. |
| 87 |
.RE |
| 88 |
.TP |
| 89 |
\fBWindows\fR |
| 90 |
. |
| 91 |
On Microsoft Windows platforms, Tcl supports both drive-relative and UNC |
| 92 |
style names. Both \fB/\fR and \fB\e\fR may be used as directory separators |
| 93 |
in either type of name. Drive-relative names consist of an optional drive |
| 94 |
specifier followed by an absolute or relative path. UNC paths follow the |
| 95 |
general form \fB\e\eservername\esharename\epath\efile\fR, but must at |
| 96 |
the very least contain the server and share components, i.e. |
| 97 |
\fB\e\eservername\esharename\fR. In both forms, |
| 98 |
the file names \fB.\fR and \fB..\fR are special and refer to the current |
| 99 |
directory and the parent of the current directory respectively. The |
| 100 |
following examples illustrate various forms of path names: |
| 101 |
.RS |
| 102 |
.TP 15 |
| 103 |
\fB\&\e\eHost\eshare/file\fR |
| 104 |
. |
| 105 |
Absolute UNC path to a file called \fBfile\fR in the root directory of |
| 106 |
the export point \fBshare\fR on the host \fBHost\fR. Note that |
| 107 |
repeated use of \fBfile dirname\fR on this path will give |
| 108 |
\fB//Host/share\fR, and will never give just \fB//Host\fR. |
| 109 |
.TP 15 |
| 110 |
\fBc:foo\fR |
| 111 |
. |
| 112 |
Volume-relative path to a file \fBfoo\fR in the current directory on drive |
| 113 |
\fBc\fR. |
| 114 |
.TP 15 |
| 115 |
\fBc:/foo\fR |
| 116 |
. |
| 117 |
Absolute path to a file \fBfoo\fR in the root directory of drive |
| 118 |
\fBc\fR. |
| 119 |
.TP 15 |
| 120 |
\fBfoo\ebar\fR |
| 121 |
. |
| 122 |
Relative path to a file \fBbar\fR in the \fBfoo\fR directory in the current |
| 123 |
directory on the current volume. |
| 124 |
.TP 15 |
| 125 |
\fB\&\efoo\fR |
| 126 |
. |
| 127 |
Volume-relative path to a file \fBfoo\fR in the root directory of the current |
| 128 |
volume. |
| 129 |
.TP 15 |
| 130 |
\fB\&\e\efoo\fR |
| 131 |
. |
| 132 |
Volume-relative path to a file \fBfoo\fR in the root directory of the current |
| 133 |
volume. This is not a valid UNC path, so the assumption is that the |
| 134 |
extra backslashes are superfluous. |
| 135 |
.RE |
| 136 |
.SH "TILDE SUBSTITUTION" |
| 137 |
.PP |
| 138 |
In addition to the file name rules described above, Tcl also supports |
| 139 |
\fIcsh\fR-style tilde substitution. If a file name starts with a tilde, |
| 140 |
then the file name will be interpreted as if the first element is |
| 141 |
replaced with the location of the home directory for the given user. If |
| 142 |
the tilde is followed immediately by a separator, then the \fB$HOME\fR |
| 143 |
environment variable is substituted. Otherwise the characters between |
| 144 |
the tilde and the next separator are taken as a user name, which is used |
| 145 |
to retrieve the user's home directory for substitution. This works on |
| 146 |
Unix, macOS and Windows (except very old releases). |
| 147 |
.PP |
| 148 |
Old Windows platforms do not support tilde substitution when a user name |
| 149 |
follows the tilde. On these platforms, attempts to use a tilde followed |
| 150 |
by a user name will generate an error that the user does not exist when |
| 151 |
Tcl attempts to interpret that part of the path or otherwise access the |
| 152 |
file. The behaviour of these paths when not trying to interpret them is |
| 153 |
the same as on Unix. File names that have a tilde without a user name |
| 154 |
will be correctly substituted using the \fB$HOME\fR environment |
| 155 |
variable, just like for Unix. |
| 156 |
.SH "PORTABILITY ISSUES" |
| 157 |
.PP |
| 158 |
Not all file systems are case sensitive, so scripts should avoid code |
| 159 |
that depends on the case of characters in a file name. In addition, |
| 160 |
the character sets allowed on different devices may differ, so scripts |
| 161 |
should choose file names that do not contain special characters like: |
| 162 |
\fB<>:?"/\e|\fR. |
| 163 |
'\""\" reset emacs highlighting |
| 164 |
The safest approach is to use names consisting of |
| 165 |
alphanumeric characters only. Care should be taken with filenames |
| 166 |
which contain spaces (common on Windows systems) and |
| 167 |
filenames where the backslash is the directory separator (Windows |
| 168 |
native path names). |
| 169 |
.PP |
| 170 |
On Windows platforms there are file and path length restrictions. |
| 171 |
Complete paths or filenames longer than about 260 characters will lead |
| 172 |
to errors in most file operations. |
| 173 |
.PP |
| 174 |
Another Windows peculiarity is that any number of trailing dots |
| 175 |
.QW . |
| 176 |
in filenames are totally ignored, so, for example, attempts to create a |
| 177 |
file or directory with a name |
| 178 |
.QW foo. |
| 179 |
will result in the creation of a file/directory with name |
| 180 |
.QW foo . |
| 181 |
This fact is reflected in the results of \fBfile normalize\fR. |
| 182 |
Furthermore, a file name consisting only of dots |
| 183 |
.QW ......... |
| 184 |
or dots with trailing characters |
| 185 |
.QW .....abc |
| 186 |
is illegal. |
| 187 |
.SH "SEE ALSO" |
| 188 |
file(n), glob(n), zipfs(n) |
| 189 |
.SH KEYWORDS |
| 190 |
current directory, absolute file name, relative file name, |
| 191 |
volume-relative file name, portability |
| 192 |
'\" Local Variables: |
| 193 |
'\" mode: nroff |
| 194 |
'\" fill-column: 78 |
| 195 |
'\" End: |