file create [file-name] [-option value...]
Create a new file. This command returns the name of a newly created command, which can be used to invoke various operations on the new file. See file open.
Options
type: bool(Default false)
Whether random access can be used.
type: integer(Default 0755)
Permission of the file
type: bool(Default false)
Whether an existing file with the same name is overwritten.
file exists [file-name]
Returns a boolean whether file file-name exist.
file info [file-name] [-option]
file info [file-name] [-option value...]
In its first form, an information about a file is returned. The option specifies, which information to return.
In its second form the values of each option must be the name of a global variable in which the corresponding information is stored. In this case the empty string is returned.
Example
puts [gnocl::file info "file:///tmp/qqq.tcl" -mimeType] gnocl::file info "file:///tmp/qqq.tcl" -isSymlink isSymlink -size fileSize -fileType type
Options
type: string
type: string
type: string
type: string
type: string
type: string
type: string
file listDir [dir-name]
Returns a list of files in a directory.
Example which lists all files starting with q, r, s or t in the home directory of the current user.
proc printFileInfo { name size } { puts "$name: $size" } gnocl::file listDir "~" -matchName {^[q-t].*} -onMatch "printFileInfo %n %s"]
Options
type: string
List only those files matching the given regular expression
type: string
Do not return a list of files, but execute the given Tcl command for each file. Before evaluation the following percent strings are substituted: TABLE %% | % %n | name %t | type %l | boolean whether file is local %k | boolean whether file is symlink %K | symlink name %m | MIME type %s | file size TABLE
file open [file-name] [-option value...]
This command opens a file and returns the name of a newly created command, which can be used to invoke various operations listed below on the file.
Options
type: bool(Default false)
Whether random access can be used.
type: one of read, r, write, w, readWrite, rw(Default read)
Open mode.
File operations
Read num-bytes bytes in the variable var. Returns the number of bytes read or -1 if EOF is encountered.
Write string.
seek position [-origin org ]
Set the file position indicator to position position. org must be one of start, current or end.
Return current position of the file position indicator
Close the file. The command associated with this file becomes invalid.
file makeDir [dir-name]
Make a directory.
Options
type: integer(Default 0755)
file remove [file-name]
Remove a file.
file removeDir [dir-name]
Remove a directory.
An example how to directly read in zip archives.
set txtFp [gnocl::file create /tmp/VFS_test.txt -force 1] $txtFp write "Gnocl with Gnome VFS" $txtFp close exec zip -j /tmp/qqq.zip /tmp/VFS_test.txt set zipFp [gnocl::file open /tmp/qqq.zip#zip:VFS_test.txt] $zipFp read 1024 ll $zipFp close puts $ll ;# will print "Gnocl with Gnome VFS"