filename(n)
β¨ filename(n) β Tcl Built-In Commands β¨
okay bestie, buckle up, we're talking about file names β specifically the file name conventions supported by Tcl commands. it's giving foundational, it's giving iykyk π
π NAME π
filename β the file name conventions that Tcl commands support. that's it, that's the girl.
πΈ INTRODUCTION πΈ
so like, every single Tcl command and C procedure that takes a file name as an argument? it expects that file name to be in one of three forms, depending on the current platform. no cap.
On each platform, Tcl supports file names in the standard form(s) for that platform. and on top of that, on all platforms, Tcl supports a Unix-like syntax that's meant to give you a convenient way to construct simple file names. cute, right?
but bestie, listen β scripts that are meant to be portable should not assume a particular form for file names. periodt. instead, portable scripts must use the file split and file join commands to manipulate file names (go read the file manual entry for the deets, it's all there).
π¦ PATH TYPES π¦
File names get grouped into three general types based on where the path starts:
- absolute β completely qualified. gives a path to the file relative to a particular volume and the root directory on that volume. fully committed, main character energy π
- relative β unqualified. gives a path to the file relative to the current working directory.
- volume-relative β partially qualified. either gives the path relative to the root directory on the current volume, or relative to the current directory of the specified volume.
and if you ever need to know which one you're dealing with? the file pathtype command will tell you. slay.
π PATH SYNTAX π
The rules for native names depend on the value reported in the platform element of the tcl_platform array:
π§ Unix
On Unix and Apple macOS platforms, Tcl uses path names where the components are separated by slashes. Path names may be relative or absolute, and file names may contain any character other than slash.
The file names . and .. are special β they refer to the current directory and the parent of the current directory respectively. Multiple adjacent slash characters are interpreted as a single separator, except for the first double slash // in absolute paths. Any number of trailing slash characters at the end of a path are simply ignored, so the paths foo, foo/ and foo// are all identical, and in particular foo/ does not necessarily mean a directory is being referred. (yes, that trips everyone up. no, you're not dumb.)
The following examples illustrate various forms of path names:
/β Absolute path to the root directory./etc/passwdβ Absolute path to the file namedpasswdin the directoryetcin the root directory..β Relative path to the current directory.fooβ Relative path to the filefooin the current directory.foo/barβ Relative path to the filebarin the directoryfooin the current directory.../fooβ Relative path to the filefooin the directory above the current directory.
πͺ Windows
On Microsoft Windows platforms, Tcl supports both drive-relative and UNC style names. Both / and \ may be used as directory separators in either type of name.
Drive-relative names consist of an optional drive specifier followed by an absolute or relative path. UNC paths follow the general form \\servername\sharename\path\file, but must at the very least contain the server and share components, i.e. \\servername\sharename.
In both forms, the file names . and .. are special and refer to the current directory and the parent of the current directory respectively.
The following examples illustrate various forms of path names:
\\Host\share/fileβ Absolute UNC path to a file calledfilein the root directory of the export pointshareon the hostHost. Note that repeated use offile dirnameon this path will give//Host/share, and will never give just//Host.c:fooβ Volume-relative path to a filefooin the current directory on drivec.c:/fooβ Absolute path to a filefooin the root directory of drivec.foo\barβ Relative path to a filebarin thefoodirectory in the current directory on the current volume.\fooβ Volume-relative path to a filefooin the root directory of the current volume.\\fooβ Volume-relative path to a filefooin the root directory of the current volume. This is not a valid UNC path, so the assumption is that the extra backslashes are superfluous.
ποΈ Zipfs
On all platforms where zipfs support is enabled, paths within mounted ZIP archives begin with the string returned by the zipfs root command. Zipfs paths are case-sensitive on all platforms. yes, even on Windows. yes, really. π
π TILDE SUBSTITUTION π
Unlike earlier versions of Tcl, Tcl 9 does not do implicit tilde substitution on file paths, with the exception noted below. The commands file home and file tildeexpand may be used to explicitly accomplish the same thing. so like, do it yourself, girlboss π«Ά
The exception to the above is initialization of the auto_path variable and the Tcl module search paths as documented in the manpages for tclvars and tm.
When any path in an environment variable used to initialize these starts with a tilde, it will be interpreted as if the first element is replaced with the location of the home directory for the given user:
- If the tilde is followed immediately by a separator, the
$HOMEenvironment variable is substituted. - Otherwise, the characters between the tilde and the next separator are taken as a user name, which is used to retrieve the user's home directory for substitution.
This works on POSIX, macOS and Windows platforms. iconic.
π PORTABILITY ISSUES π
Not all file systems are case sensitive, so scripts should avoid code that depends on the case of characters in a file name. (iykyk β your laptop might not care but the server will absolutely humble you.)
In addition, the character sets allowed on different devices may differ, so scripts should choose file names that do not contain special characters like:
<>:?"/\|
The safest approach is to use names consisting of alphanumeric characters only. Care should be taken with filenames which contain spaces (common on Windows systems) and filenames where the backslash is the directory separator (Windows native path names).
π¨ On Windows platforms there are file and path length restrictions. Complete paths or filenames longer than about 260 characters will lead to errors in most file operations. that's not a vibe.
Another Windows peculiarity is that any number of trailing dots . in filenames are totally ignored, so, for example, attempts to create a file or directory with a name foo. will result in the creation of a file/directory with name foo. This fact is reflected in the results of file normalize. Furthermore, a file name consisting only of dots ......... or dots with trailing characters .....abc is illegal. π
π SEE ALSO π
π KEYWORDS π
current directory, absolute file name, relative file name, volume-relative file name, portability
and that's the whole page, bestie!! this one came from the Tcl corner of the world, version 7.5, and it's the filename(n) entry β go forth and name your files responsibly, mwah πβ¨π
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- nixpkgs unstable: tcl 9.1.0
- Copyright (c) 1995-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms