The file Command

   

Practical Programming in Tcl & Tk, Third Edition
By Brent B. Welch

Table of Contents
Chapter 9.  Working with Files and Programs


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 the split, join, and pathtype operations were added in Tcl 7.5. The copy, delete, mkdir, and rename operations were added in Tcl 7.6. The attributes operation was added in Tcl 8.0

Table 9-2. The file command options.
file atime nameReturns access time as a decimal string.
file attributes name ?option? ?value? ...Queries or sets file attributes. (Tcl 8.0)
file copy ?-force? source destinationCopies file source to file destination. The source and destination can be directories. (Tcl 7.6)
file delete ?-force? nameDeletes the named file. (Tcl 7.6)
file dirname nameReturns parent directory of file name.
file executable nameReturns 1 if name has execute permission, else 0.
file exists nameReturns 1 if name exists, else 0.
file extension nameReturns the part of name from the last dot (i.e., .) to the end. The dot is included in the return value.
file isdirectory nameReturns 1 if name is a directory, else 0.
file isfile nameReturns 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 lstat name varPlaces attributes of the link name into var.
file mkdir nameCreates directory name. (Tcl 7.6)
file mtime nameReturns modify time of name as a decimal string.
file nativename nameReturns the platform-native version of name. (Tk 8.0).
file owned nameReturns 1 if current user owns the file name, else 0.
file pathtype namerelative, absolute, or driverelative. (Tcl 7.5)
file readable nameReturns 1 if name has read permission, else 0.
file readlink nameReturns the contents of the symbolic link name.
file rename ?-force? old newChanges the name of old to new. (Tcl 7.6)
file rootname nameReturns all but the extension of name (i.e., up to but not including the last . in name).
file size nameReturns the number of bytes in name.
file split nameSplits name into its pathname components. (Tcl 7.5)
file stat name varPlaces attributes of name into array var. The elements defined for var are listed in Table 9-3.
file tail nameReturns the last pathname component of name.
file type nameReturns type identifier, which is one of: file, directory, characterSpecial, blockSpecial, fifo, link, or socket.
file writable nameReturns 1 if name has write permission, else 0.


       
    Top
     



    Practical Programming in Tcl and Tk
    Practical Programming in Tcl and Tk (4th Edition)
    ISBN: 0130385603
    EAN: 2147483647
    Year: 1999
    Pages: 478

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net