filename(n)

πŸ“¦
version 9.0.3 Β· 4 versions
, in alpine 3.23, alpine 3.24, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

✨ 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 named passwd in the directory etc in the root directory.
  • . β€” Relative path to the current directory.
  • foo β€” Relative path to the file foo in the current directory.
  • foo/bar β€” Relative path to the file bar in the directory foo in the current directory.
  • ../foo β€” Relative path to the file foo in 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 called file in the root directory of the export point share on the host Host. Note that repeated use of file dirname on this path will give //Host/share, and will never give just //Host.
  • c:foo β€” Volume-relative path to a file foo in the current directory on drive c.
  • c:/foo β€” Absolute path to a file foo in the root directory of drive c.
  • foo\bar β€” Relative path to a file bar in the foo directory in the current directory on the current volume.
  • \foo β€” Volume-relative path to a file foo in the root directory of the current volume.
  • \\foo β€” Volume-relative path to a file foo in 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 $HOME environment 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