1filename(n)                  Tcl Built-In Commands                 filename(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       filename - File name conventions supported by Tcl commands
9_________________________________________________________________
10

INTRODUCTION

12       All  Tcl  commands  and  C procedures that take file names as arguments
13       expect the file names to be in one of three  forms,  depending  on  the
14       current  platform.   On  each  platform, Tcl supports file names in the
15       standard forms(s) for that platform.  In addition,  on  all  platforms,
16       Tcl 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.
19       Instead, portable scripts must use the file split and  file  join  com‐
20       mands  to  manipulate  file  names  (see the file manual entry for more
21       details).
22
23

PATH TYPES

25       File names are grouped into three general types based on  the  starting
26       point  for  the  path used to specify the file: absolute, relative, and
27       volume-relative.  Absolute names are  completely  qualified,  giving  a
28       path to the file relative to a particular volume and the root directory
29       on that volume.  Relative names are unqualified, giving a path  to  the
30       file  relative to the current working directory.  Volume-relative names
31       are partially qualified, either giving the path relative  to  the  root
32       directory  on  the current volume, or relative to the current directory
33       of the specified volume.  The file pathtype  command  can  be  used  to
34       determine the type of a given path.
35
36

PATH SYNTAX

38       The  rules  for  native  names  depend on the value reported in the Tcl
39       array element tcl_platform(platform):
40
41       mac       On Apple Macintosh systems, Tcl supports two  forms  of  path
42                 names.  The normal Mac style names use colons as path separa‐
43                 tors.  Paths may be relative or absolute, and file names  may
44                 contain  any  character  other  than  colon.  A leading colon
45                 causes the rest of the path to be interpreted relative to the
46                 current directory.  If a path contains a colon that is not at
47                 the beginning, then the path is interpreted  as  an  absolute
48                 path.   Sequences  of two or more colons anywhere in the path
49                 are used to construct relative paths where :: refers  to  the
50                 parent  of the current directory, ::: refers to the parent of
51                 the parent, and so forth.
52
53                 In addition to Macintosh style names,  Tcl  also  supports  a
54                 subset  of  Unix-like  names.   If a path contains no colons,
55                 then it is interpreted like a Unix path.  Slash  is  used  as
56                 the  path  separator.   The file name . refers to the current
57                 directory, and .. refers to the parent of the current  direc‐
58                 tory.  However, some names like / or /.. have no mapping, and
59                 are interpreted as Macintosh  names.   In  general,  commands
60                 that  generate  file names will return Macintosh style names,
61                 but commands that accept file names will take both  Macintosh
62                 and Unix-style names.
63
64                 The  following  examples  illustrate  various  forms  of path
65                 names:
66
67                 :              Relative path to the current folder.
68
69                 MyFile         Relative path to a file named  MyFile  in  the
70                                current folder.
71
72                 MyDisk:MyFile  Absolute  path  to  a file named MyFile on the
73                                device named MyDisk.
74
75                 :MyDir:MyFile  Relative path to  a  file  name  MyFile  in  a
76                                folder named MyDir in the current folder.
77
78                 ::MyFile       Relative  path  to  a file named MyFile in the
79                                folder above the current folder.
80
81                 :::MyFile      Relative path to a file named  MyFile  in  the
82                                folder two levels above the current folder.
83
84                 /MyDisk/MyFile Absolute  path  to  a file named MyFile on the
85                                device named MyDisk.
86
87                 ../MyFile      Relative path to a file named  MyFile  in  the
88                                folder above the current folder.
89
90       unix      On  Unix  platforms, Tcl uses path names where the components
91                 are separated by slashes.  Path  names  may  be  relative  or
92                 absolute, and file names may contain any character other than
93                 slash.  The file names . and .. are special and refer to  the
94                 current  directory  and  the  parent of the current directory
95                 respectively.  Multiple adjacent slash characters are  inter‐
96                 preted  as a single separator.  The following examples illus‐
97                 trate various forms of path names:
98
99                 /              Absolute path to the root directory.
100
101                 /etc/passwd    Absolute path to the file named passwd in  the
102                                directory etc in the root directory.
103
104                 .              Relative path to the current directory.
105
106                 foo            Relative  path  to the file foo in the current
107                                directory.
108
109                 foo/bar        Relative path to the file bar in the directory
110                                foo in the current directory.
111
112                 ../foo         Relative path to the file foo in the directory
113                                above the current directory.
114
115       windows   On Microsoft Windows platforms, Tcl supports both drive-rela‐
116                 tive and UNC style names.  Both / and \ may be used as direc‐
117                 tory separators in either type of name.  Drive-relative names
118                 consist  of  an optional drive specifier followed by an abso‐
119                 lute or relative path.  UNC paths  follow  the  general  form
120                 \\servername\sharename\path\file,  but must at the very least
121                 contain the server  and  share  components,  i.e.   \\server‐
122                 name\sharename.   In  both forms, the file names . and .. are
123                 special and refer to the current directory and the parent  of
124                 the  current  directory respectively.  The following examples
125                 illustrate various forms of path names:
126
127                 \\Host\share/file
128                                Absolute UNC path to a file called file in the
129                                root  directory  of  the export point share on
130                                the host Host.  Note that repeated use of file
131                                dirname  on  this path will give //Host/share,
132                                and will never give just /fB//Host/fR.
133
134                 c:foo          Volume-relative path to a file foo in the cur‐
135                                rent directory on drive c.
136
137                 c:/foo         Absolute path to a file foo in the root direc‐
138                                tory of drive c.
139
140                 foo\bar        Relative path to a file bar in the foo  direc‐
141                                tory  in  the current directory on the current
142                                volume.
143
144                 \foo           Volume-relative path to a file foo in the root
145                                directory of the current volume.
146
147                 \\foo          Volume-relative path to a file foo in the root
148                                directory of the current volume.  This is  not
149                                a  valid  UNC  path, so the assumption is that
150                                the extra backslashes are superfluous.
151
152

TILDE SUBSTITUTION

154       In addition to the file name rules described above, Tcl  also  supports
155       csh-style tilde substitution.  If a file name starts with a tilde, then
156       the file name will be interpreted as if the first element  is  replaced
157       with  the  location  of  the home directory for the given user.  If the
158       tilde is followed immediately by a separator, then the  $HOME  environ‐
159       ment  variable  is  substituted.   Otherwise the characters between the
160       tilde and the next separator are taken as a user name, which is used to
161       retrieve the user's home directory for substitution.
162
163       The  Macintosh  and Windows platforms do not support tilde substitution
164       when a user name follows the tilde.  On these  platforms,  attempts  to
165       use  a  tilde  followed  by a user name will generate an error that the
166       user does not exist when Tcl attempts to interpret  that  part  of  the
167       path  or  otherwise access the file.  The behaviour of these paths when
168       not trying to interpret them is the same as on Unix.  File  names  that
169       have  a  tilde  without a user name will be correctly substituted using
170       the $HOME environment variable, just like for Unix.
171
172

PORTABILITY ISSUES

174       Not all file systems are case sensitive, so scripts should  avoid  code
175       that  depends  on  the case of characters in a file name.  In addition,
176       the character sets allowed on different devices may differ, so  scripts
177       should  choose  file names that do not contain special characters like:
178       <>:"/\|.  The safest approach is to use names  consisting  of  alphanu‐
179       meric  characters only.  Also Windows 3.1 only supports file names with
180       a root of no more than 8 characters and an extension of no more than  3
181       characters.
182
183       On Windows platforms there are file and path length restrictions.  Com‐
184       plete paths or filenames longer than about 260 characters will lead  to
185       errors in most file operations.
186
187       Another Windows peculiarity is that any number of trailing dots '.'  in
188       filenames are totally ignored, so, for example, attempts  to  create  a
189       file  or  directory with a name "foo." will result in the creation of a
190       file/directory with name "foo".  This fact is reflected in the  results
191       of  'file normalize'.  Furthermore, a file name consisting only of dots
192       '.........' or dots with trailing characters '.....abc' is illegal.
193

KEYWORDS

195       current directory, absolute file name, relative file name, volume-rela‐
196       tive file name, portability
197
198

SEE ALSO

200       file(n), glob(n)
201
202
203
204Tcl                                   7.5                          filename(n)
Impressum