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