1filename(n) Tcl Built-In Commands filename(n)
2
3
4
5______________________________________________________________________________
6
8 filename - File name conventions supported by Tcl commands
9______________________________________________________________________________
10
12 All Tcl commands and C procedures that take file names as arguments ex‐
13 pect the file names to be in one of three forms, depending on the cur‐
14 rent platform. On each platform, Tcl supports file names in the stan‐
15 dard forms(s) for that platform. In addition, on all platforms, Tcl
16 supports a Unix-like syntax intended to provide a convenient way of
17 constructing simple file names. However, scripts that are intended to
18 be portable should not assume a particular form for file names. In‐
19 stead, portable scripts must use the file split and file join commands
20 to manipulate file names (see the file manual entry for more details).
21
23 File names are grouped into three general types based on the starting
24 point for the path used to specify the file: absolute, relative, and
25 volume-relative. Absolute names are completely qualified, giving a
26 path to the file relative to a particular volume and the root directory
27 on that volume. Relative names are unqualified, giving a path to the
28 file relative to the current working directory. Volume-relative names
29 are partially qualified, either giving the path relative to the root
30 directory on the current volume, or relative to the current directory
31 of the specified volume. The file pathtype command can be used to de‐
32 termine the type of a given path.
33
35 The rules for native names depend on the value reported in the Tcl
36 platform element of the tcl_platform array:
37
38 Unix On Unix and Apple MacOS X platforms, Tcl uses path names
39 where the components are separated by slashes. Path names
40 may be relative or absolute, and file names may contain any
41 character other than slash. The file names . and .. are spe‐
42 cial and refer to the current directory and the parent of the
43 current directory respectively. Multiple adjacent slash
44 characters are interpreted as a single separator. Any number
45 of trailing slash characters at the end of a path are simply
46 ignored, so the paths foo, foo/ and foo// are all identical,
47 and in particular foo/ does not necessarily mean a directory
48 is being referred.
49
50 The following examples illustrate various forms of path
51 names:
52
53 / Absolute path to the root directory.
54
55 /etc/passwd Absolute path to the file named passwd in the
56 directory etc in the root directory.
57
58 . Relative path to the current directory.
59
60 foo Relative path to the file foo in the current
61 directory.
62
63 foo/bar Relative path to the file bar in the directory
64 foo in the current directory.
65
66 ../foo Relative path to the file foo in the directory
67 above the current directory.
68
69 Windows On Microsoft Windows platforms, Tcl supports both drive-rela‐
70 tive and UNC style names. Both / and \ may be used as direc‐
71 tory separators in either type of name. Drive-relative names
72 consist of an optional drive specifier followed by an abso‐
73 lute or relative path. UNC paths follow the general form
74 \\servername\sharename\path\file, but must at the very least
75 contain the server and share components, i.e. \\server‐
76 name\sharename. In both forms, the file names . and .. are
77 special and refer to the current directory and the parent of
78 the current directory respectively. The following examples
79 illustrate various forms of path names:
80
81 \\Host\share/file
82 Absolute UNC path to a file called file in the
83 root directory of the export point share on
84 the host Host. Note that repeated use of file
85 dirname on this path will give //Host/share,
86 and will never give just //Host.
87
88 c:foo Volume-relative path to a file foo in the cur‐
89 rent directory on drive c.
90
91 c:/foo Absolute path to a file foo in the root direc‐
92 tory of drive c.
93
94 foo\bar Relative path to a file bar in the foo direc‐
95 tory in the current directory on the current
96 volume.
97
98 \foo Volume-relative path to a file foo in the root
99 directory of the current volume.
100
101 \\foo Volume-relative path to a file foo in the root
102 directory of the current volume. This is not
103 a valid UNC path, so the assumption is that
104 the extra backslashes are superfluous.
105
107 In addition to the file name rules described above, Tcl also supports
108 csh-style tilde substitution. If a file name starts with a tilde, then
109 the file name will be interpreted as if the first element is replaced
110 with the location of the home directory for the given user. If the
111 tilde is followed immediately by a separator, then the $HOME environ‐
112 ment variable is substituted. Otherwise the characters between the
113 tilde and the next separator are taken as a user name, which is used to
114 retrieve the user's home directory for substitution. This works on
115 Unix, MacOS X and Windows (except very old releases).
116
117 Old Windows platforms do not support tilde substitution when a user
118 name follows the tilde. On these platforms, attempts to use a tilde
119 followed by a user name will generate an error that the user does not
120 exist when Tcl attempts to interpret that part of the path or otherwise
121 access the file. The behaviour of these paths when not trying to in‐
122 terpret them is the same as on Unix. File names that have a tilde
123 without a user name will be correctly substituted using the $HOME envi‐
124 ronment variable, just like for Unix.
125
127 Not all file systems are case sensitive, so scripts should avoid code
128 that depends on the case of characters in a file name. In addition,
129 the character sets allowed on different devices may differ, so scripts
130 should choose file names that do not contain special characters like:
131 <>:?"/\|. The safest approach is to use names consisting of alphanu‐
132 meric characters only. Care should be taken with filenames which con‐
133 tain spaces (common on Windows systems) and filenames where the back‐
134 slash is the directory separator (Windows native path names).
135
136 On Windows platforms there are file and path length restrictions. Com‐
137 plete paths or filenames longer than about 260 characters will lead to
138 errors in most file operations.
139
140 Another Windows peculiarity is that any number of trailing dots “.” in
141 filenames are totally ignored, so, for example, attempts to create a
142 file or directory with a name “foo.” will result in the creation of a
143 file/directory with name “foo”. This fact is reflected in the results
144 of file normalize. Furthermore, a file name consisting only of dots
145 “.........” or dots with trailing characters “.....abc” is illegal.
146
148 file(n), glob(n)
149
151 current directory, absolute file name, relative file name, volume-rela‐
152 tive file name, portability
153
154
155
156Tcl 7.5 filename(n)