[ Team LiB ] Previous Section Next Section

The file Command

The file command provides several ways to check the status of files in the file system. For example, you can find out if a file exists, what type of file it is, and other file attributes. There are facilities for manipulating files in a platform-independent manner. Table 9-2 provides a summary of the various forms of the file command. They are described in more detail later. Note that several operations have been added since the introduction of the file command; the table indicates the version of Tcl in which they were added.

Table 9-2. The file command options

file atime name ?time?

Returns access time as a decimal string. If time is specified, the access time of the file is set.

file attributes name ?option? ?value? ...

Queries or sets file attributes. (Tcl 8.0)

file channels ?pattern?

Returns the open channels in this interpreter, optionally filtered by the glob-style pattern. (Tcl 8.3)

file copy ?-force? source destination

Copies file source to file destination. The source and destination can be directories. (Tcl 7.6)

file delete ?-force? name

Deletes the named file. (Tcl 7.6)

file dirname name

Returns parent directory of file name.

file executable name

Returns 1 if name has execute permission, else 0.

file exists name

Returns 1 if name exists, else 0.

file extension name

Returns the part of name from the last dot (i.e., .) to the end. The dot is included in the return value.

file isdirectory name

Returns 1 if name is a directory, else 0.

file isfile name

Returns 1 if name is not a directory, symbolic link, or device, else 0.

file join path path...

Joins pathname components into a new pathname. (Tcl 7.5)

file link ?-type? name ?target?

Returns the link pointed to by name, or creates a link to target if it is specified. type can be -hard or -symbolic. (Tcl 8.4)

file lstat name var

Places attributes of the link name into var.

file mkdir name

Creates directory name. (Tcl 7.6)

file mtime name ?time?

Returns modify time of name as a decimal string. If time is specified, the modify time of the file is set.

file nativename name

Returns the platform-native version of name. (Tk 8.0).

file normalize name

Returns a unique, absolute, path for name while eliminating extra /, /., and /.. components. (Tcl 8.4)

file owned name

Returns 1 if current user owns the file name, else 0.

file pathtype name

relative, absolute, or volumerelative. (Tcl 7.5)

file readable name

Returns 1 if name has read permission, else 0.

file readlink name

Returns the contents of the symbolic link name.

file rename ?-force? old new

Changes the name of old to new. (Tcl 7.6)

file rootname name

Returns all but the extension of name (i.e., up to but not including the last . in name).

file separator ?name?

Returns the default file separator character on this file system, or the separator character for name if it is specified. (Tcl 8.4)

file size name

Returns the number of bytes in name.

file split name

Splits name into its pathname components. (Tcl 7.5)

file stat name var

Places attributes of name into array var. The elements defined for var are listed in Table 9-3.

file system name

Returns a tuple of the filesystem for name (e.g. native or vfs) and the platform-specific type for name (e.g NTFS or FAT32). (Tcl 8.4)

file tail name

Returns the last pathname component of name.

file type name

Returns type identifier, which is one of: file, directory, characterSpecial, blockSpecial, fifo, link, or socket.

file volumes name

Returns the available file volumes on this computer. On Unix, this always returns /. On Windows, this would be a list like {a:/ c:/}. (Tcl 8.3)

file writable name

Returns 1 if name has write permission, else 0.

    [ Team LiB ] Previous Section Next Section