file(1,n)(n) Tcl Built-In Commands file(1,n)(n) NAME file(1,n) - Manipulate file(1,n) names and attributes SYNOPSIS file(1,n) option name ?arg arg ...? DESCRIPTION This command provides several operations on a file(1,n)'s name or attributes. Name is the name of a file(1,n); if(3,n) it starts with a tilde, then tilde substitution is done before executing the command (see the manual entry for filename for details). Option indicates what to do with the file(1,n) name. Any unique abbreviation for option is acceptable. The valid options are: file(1,n) atime name ?time(1,2,n)? Returns a decimal string(3,n) giving the time(1,2,n) at which file(1,n) name was last accessed. If time(1,2,n) is specified, it is an access(2,5) time(1,2,n) to set(7,n,1 builtins) for the file. The time(1,2,n) is measured in(1,8) the standard POSIX fashion as seconds from a fixed starting time(1,2,n) (often January 1, 1970). If the file(1,n) doesn't exist or its access(2,5) time(1,2,n) cannot be queried or set(7,n,1 builtins) then an error(8,n) is generated. On Windows, FAT file(1,n) systems do not support access(2,5) time. file(1,n) attributes name file(1,n) attributes name ?option? file(1,n) attributes name ?option value option value...? This subcommand returns or sets platform specific values associ- ated with a file. The first form returns a list of the platform specific flags and their values. The second form returns the value for the specific option. The third form sets one or more of the values. The values are as follows: On Unix, -group gets(3,n) or sets the group name for the file. A group id can be given to the command, but it returns a group name. -owner gets(3,n) or sets the user name of the owner of the file. The command returns the owner name, but the numerical id can be passed when setting the owner. -permissions sets or retrieves the octal code that chmod(1,2)(1) uses. This command does also has limited support for setting using the symbolic attributes for chmod(1,2)(1), of the form [ugo]?[[+-=][rwxst],[...]], where multiple symbolic attributes can be separated by commas (example: u+s,go-rw add sticky bit for user, remove read(2,n,1 builtins) and write(1,2) permissions for group and other). A simplified ls style string(3,n), of the form rwxrwxrwx (must be 9 characters), is also supported (example: rwxr-xr-t is equivalent to 01755). On Windows, -archive gives the value or sets or clears the ar- chive attribute of the file. -hidden gives the value or sets or clears the hidden attribute of the file. -longname will expand each path element to its long version. This attribute cannot be set. -readonly gives the value or sets or clears the readonly attribute of the file. -shortname gives a string(3,n) where every path element is replaced with its short (8.3) version(1,3,5) of the name. This attribute cannot be set. -system gives or sets or clears the value of the system attribute of the file. On Macintosh, -creator gives or sets the Finder creator type of the file. -hidden gives or sets or clears the hidden attribute of the file. -readonly gives or sets or clears the readonly attribute of the file. Note that directories can only be locked if(3,n) File Sharing is turned on. -type gives or sets the Finder file(1,n) type for the file. file(1,n) channels ?pattern? If pattern isn't specified, returns a list of names of all reg- istered open(2,3,n) channels in(1,8) this interpreter. If pattern is speci- fied, only those names matching pattern are returned. Matching is determined using the same rules as for string(3,n) match. file(1,n) copy ?-force? ?--? source target file(1,n) copy ?-force? ?--? source ?source ...? targetDir The first form makes a copy of the file(1,n) or directory source under the pathname target. If target is an existing directory, then the second form is used. The second form makes a copy inside targetDir of each source file(1,n) listed. If a directory is specified as a source, then the contents of the directory will be recursively copied into targetDir. Existing files will not be overwritten unless the -force option is specified. When copying within a single filesystem, file(1,n) copy will copy soft links (i.e. the links themselves are copied, not the things they point to). Trying to overwrite a non-empty directory, overwrite a directory with a file(1,n), or a file(1,n) with a directory will all result in(1,8) errors even if(3,n) -force was specified. Arguments are processed in(1,8) the order specified, halting at the first error(8,n), if(3,n) any. A -- marks the end of switches; the argument following the -- will be treated as a source even if(3,n) it starts with a -. file(1,n) delete ?-force? ?--? pathname ?pathname ... ? Removes the file(1,n) or directory specified by each pathname argu- ment. Non-empty directories will be removed only if(3,n) the -force option is specified. When operating on symbolic links, the links themselves will be deleted, not the objects they point to. Trying to delete a non-existent file(1,n) is not considered an error. Trying to delete a read-only file(1,n) will cause the file(1,n) to be deleted, even if(3,n) the -force flags is not specified. If the -force option is specified on a directory, Tcl will attempt both to change permissions and move(3x,7,3x curs_move) the current directory 'pwd(1,n,1 builtins)' out of the given path if(3,n) that is necessary to allow the deletion to proceed. Arguments are processed in(1,8) the order specified, halt- ing at the first error(8,n), if(3,n) any. A -- marks the end of switches; the argument following the -- will be treated as a pathname even if(3,n) it starts with a -. file(1,n) dirname name Returns a name comprised of all of the path components in(1,8) name excluding the last element. If name is a relative file(1,n) name and only contains one path element, then returns ``.'' (or ``:'' on the Macintosh). If name refers to a root directory, then the root directory is returned. For example, file(1,n) dirname c:/ returns c:/. Note that tilde substitution will only be performed if(3,n) it is necessary to complete the command. For example, file(1,n) dirname ~/src/foo.c returns ~/src, whereas file(1,n) dirname ~ returns /home (or something similar). file(1,n) executable name Returns 1 if(3,n) file(1,n) name is executable by the current user, 0 oth- erwise. file(1,n) exists name Returns 1 if(3,n) file(1,n) name exists and the current user has search privileges for the directories leading to it, 0 otherwise. file(1,n) extension name Returns all of the characters in(1,8) name after and including the last dot in(1,8) the last element of name. If there is no dot in(1,8) the last element of name then returns the empty string. file(1,n) isdirectory name Returns 1 if(3,n) file(1,n) name is a directory, 0 otherwise. file(1,n) isfile name Returns 1 if(3,n) file(1,n) name is a regular file(1,n), 0 otherwise. file(1,n) join(1,n) name ?name ...? Takes one or more file(1,n) names and combines them, using the cor- rect path separator for the current platform. If a particular name is relative, then it will be joined to the previous file(1,n) name argument. Otherwise, any earlier arguments will be dis- carded, and joining will proceed from the current argument. For example, file(1,n) join(1,n) a b /foo bar returns /foo/bar. Note that any of the names can contain separators, and that the result is always canonical for the current platform: / for Unix and Windows, and : for Macintosh. file(1,n) link(1,2) ?-linktype? linkName ?target? If only one argument is given, that argument is assumed to be linkName, and this command returns the value of the link(1,2) given by linkName (i.e. the name of the file(1,n) it points to). If linkName isn't a link(1,2) or its value cannot be read(2,n,1 builtins) (as, for exam- ple, seems to be the case with hard links, which look(1,8,3 Search::Dict) just like ordinary files), then an error(8,n) is returned. If 2 arguments are given, then these are assumed to be linkName and target. If linkName already exists, or if(3,n) target doesn't exist, an error(8,n) will be returned. Otherwise, Tcl creates a new link(1,2) called linkName which points to the existing filesystem object at tar- get, where the type of the link(1,2) is platform-specific (on Unix a symbolic link(1,2) will be the default). This is useful for the case where the user wishes to create a link(1,2) in(1,8) a cross-platform way, and doesn't care what type of link(1,2) is created. If the user wishes to make a link(1,2) of a specific type only, (and signal(2,7) an error(8,n) if(3,n) for some reason that is not possible), then the optional -linktype argument should be given. Accepted values for -linktype are "-symbolic" and "-hard". When creating links on filesystems that either do not support any links, or do not support the specific type requested, an error(8,n) message will be returned. In particular Windows 95, 98 and ME do not support any links at present, but most Unix platforms support both sym- bolic and hard links (the latter for files only), MacOS supports symbolic links and Windows NT/2000/XP (on NTFS drives) support symbolic directory links and hard file(1,n) links. file(1,n) lstat name varName Same as stat(1,2) option (see below) except uses the lstat kernel call instead of stat(1,2). This means that if(3,n) name refers to a sym- bolic link(1,2) the information returned in(1,8) varName is for the link(1,2) rather than the file(1,n) it refers to. On systems that don't sup- port symbolic links this option behaves exactly the same as the stat(1,2) option. file(1,n) mkdir(1,2) dir ?dir ...? Creates each directory specified. For each pathname dir speci- fied, this command will create all non-existing parent directo- ries as well as dir itself. If an existing directory is speci- fied, then no action is taken and no error(8,n) is returned. Trying to overwrite an existing file(1,n) with a directory will result in(1,8) an error. Arguments are processed in(1,8) the order specified, halting at the first error(8,n), if(3,n) any. file(1,n) mtime name ?time(1,2,n)? Returns a decimal string(3,n) giving the time(1,2,n) at which file(1,n) name was last modified. If time(1,2,n) is specified, it is a modification time(1,2,n) to set(7,n,1 builtins) for the file(1,n) (equivalent to Unix touch). The time(1,2,n) is measured in(1,8) the standard POSIX fashion as seconds from a fixed starting time(1,2,n) (often January 1, 1970). If the file(1,n) doesn't exist or its modified time(1,2,n) cannot be queried or set(7,n,1 builtins) then an error(8,n) is generated. file(1,n) nativename name Returns the platform-specific name of the file. This is useful if(3,n) the filename is needed to pass to a platform-specific call, such as exec(3,n,1 builtins) under Windows or AppleScript on the Macintosh. file(1,n) normalize name Returns a unique normalised path representation for the file- system object (file(1,n), directory, link(1,2), etc), whose string(3,n) value can be used as a unique identifier for it. A normalized path is an absolute path which has all '../', './' removed. Also it is one which is in(1,8) the ``standard'' format for the native platform. On MacOS, Unix, this means the segments leading up to the path must be free of symbolic links/aliases (but the very last path component may be a symbolic link(1,2)), and on Windows it also means means we want the long form with that form's case-dependence (which gives us a unique, case-dependent path). The one excep- tion concerning the last link(1,2) in(1,8) the path is necessary, because Tcl or the user may wish to operate on the actual symbolic link(1,2) itself (for example 'file(1,n) delete', 'file(1,n) rename(1,2,n)', 'file(1,n) copy' are defined to operate on symbolic links, not on the things that they point to). file(1,n) owned name Returns 1 if(3,n) file(1,n) name is owned by the current user, 0 other- wise. file(1,n) pathtype name Returns one of absolute, relative, volumerelative. If name refers to a specific file(1,n) on a specific volume, the path type will be absolute. If name refers to a file(1,n) relative to the cur- rent working directory, then the path type will be relative. If name refers to a file(1,n) relative to the current working directory on a specified volume, or to a specific file(1,n) on the current working volume, then the file(1,n) type is volumerelative. file(1,n) readable name Returns 1 if(3,n) file(1,n) name is readable by the current user, 0 other- wise. file(1,n) readlink(1,2) name Returns the value of the symbolic link(1,2) given by name (i.e. the name of the file(1,n) it points to). If name isn't a symbolic link(1,2) or its value cannot be read(2,n,1 builtins), then an error(8,n) is returned. On sys- tems that don't support symbolic links this option is undefined. file(1,n) rename(1,2,n) ?-force? ?--? source target file(1,n) rename(1,2,n) ?-force? ?--? source ?source ...? targetDir The first form takes the file(1,n) or directory specified by pathname source and renames it to target, moving the file(1,n) if(3,n) the pathname target specifies a name in(1,8) a different directory. If target is an existing directory, then the second form is used. The second form moves each source file(1,n) or directory into the directory tar- getDir. Existing files will not be overwritten unless the -force option is specified. When operating inside a single filesystem, Tcl will rename(1,2,n) symbolic links rather than the things that they point to. Trying to overwrite a non-empty directory, overwrite a directory with a file(1,n), or a file(1,n) with a directory will all result in(1,8) errors. Arguments are processed in(1,8) the order speci- fied, halting at the first error(8,n), if(3,n) any. A -- marks the end of switches; the argument following the -- will be treated as a source even if(3,n) it starts with a -. file(1,n) rootname name Returns all of the characters in(1,8) name up to but not including the last ``.'' character in(1,8) the last component of name. If the last component of name doesn't contain a dot, then returns name. file(1,n) separator ?name? If no argument is given, returns the character which is used to separate path segments for native files on this platform. If a path is given, the filesystem responsible for that path is asked to return its separator character. If no file(1,n) system accepts name, an error(8,n) is generated. file(1,n) size name Returns a decimal string(3,n) giving the size of file(1,n) name in(1,8) bytes. If the file(1,n) doesn't exist or its size cannot be queried then an error(8,n) is generated. file(1,n) split(1,n) name Returns a list whose elements are the path components in(1,8) name. The first element of the list will have the same path type as name. All other elements will be relative. Path separators will be discarded unless they are needed ensure that an element is unambiguously relative. For example, under Unix file(1,n) split(1,n) /foo/~bar/baz returns / foo ./~bar baz to ensure that later commands that use the third component do not attempt to perform tilde substitution. file(1,n) stat(1,2) name varName Invokes the stat(1,2) kernel call on name, and uses the variable given by varName to hold information returned from the kernel call. VarName is treated as an array variable, and the follow- ing elements of that variable are set: atime, ctime, dev, gid, ino, mode, mtime, nlink, size, type, uid. Each element except type is a decimal string(3,n) with the value of the corresponding field from the stat(1,2) return structure; see the manual entry for stat(1,2) for details on the meanings of the values. The type ele- ment gives the type of the file(1,n) in(1,8) the same form returned by the command file(1,n) type. This command returns an empty string. file(1,n) system name Returns a list of two elements, the first of which is the name of the filesystem to use for the file(1,n), and the second an arbi- trary string(3,n) representing the filesystem-specific nature or type of the location within that filesystem. If a filesystem only supports one type of file(1,n), the second element may be null. For example the native files have a first element 'native', and a second element which is a platform-specific type name for the file(1,n)'s system (e.g. 'NTFS', 'FAT', etc), or possibly the empty string(3,n) if(3,n) no further information is available or if(3,n) this is not implemented. A generic virtual(5,8) file(1,n) system might return the list 'vfs ftp' to represent a file(1,n) on a remote ftp site mounted as a virtual(5,8) filesystem through an extension called 'vfs'. If the file(1,n) does not belong to any filesystem, an error(8,n) is gener- ated. file(1,n) tail name Returns all of the characters in(1,8) name after the last directory separator. If name contains no separators then returns name. file(1,n) type name Returns a string(3,n) giving the type of file(1,n) name, which will be one of file(1,n), directory, characterSpecial, blockSpecial, fifo, link(1,2), or socket(2,7,n). file(1,n) volumes Returns the absolute paths to the volumes mounted on the system, as a proper Tcl list. On the Macintosh, this will be a list of the mounted drives, both local and network. N.B. if(3,n) two drives have the same name, they will both appear on the volume list, but there is currently no way, from Tcl, to access(2,5) any but the first of these drives. On UNIX, the command will always return "/", since all filesystems are locally mounted. On Windows, it will return a list of the available local drives (e.g. {a:/ c:/}). file(1,n) writable name Returns 1 if(3,n) file(1,n) name is writable by the current user, 0 other- wise. PORTABILITY ISSUES Unix These commands always operate using the real user and group identifiers, not the effective ones. SEE ALSO filename(n), open(2,3,n)(n), close(2,7,n)(n), eof(n), gets(3,n)(n), tell(n), seek(n), fblocked(n), flush(8,n)(n) KEYWORDS attributes, copy files, delete files, directory, file(1,n), move(3x,7,3x curs_move) files, name, rename(1,2,n) files, stat(1,2) Tcl 8.3 file(1,n)(n)