Packages‎ > ‎gnocl::vfs‎ > ‎

gnocl::file

Implement virtual file system commands

Synopsis

file [subcommand] [-option value...]

Description

The file command implements Gnome virtual file system commands.

Subcommands

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

-random

type: boolean  (Default false)

Whether random access can be used.

-permission

type: integer(Default 0755)

Permission of the file

-force

type: boolean (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

-fileType

type: string

-isLocal

type: string

-isSymlink

type: string

-mimeType

type: string

-name

type: string

-size

type: string

-symlinkName

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

-matchName

type: string

List only those files matching the given regular expression

-onMatch

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

-random

type: bool(Default false)

Whether random access can be used.

-mode

type: one of read, r, write, w, readWrite, rw(Default read)

Open mode.

File operations

read num-bytes var

Read num-bytes bytes in the variable var. Returns the number of bytes read or -1 if EOF is encountered.

write string

Write string.

seek position [-origin org ]

Set the file position indicator to position position. org must be one of start, current or end.

tell

Return current position of the file position indicator

close

Close the file. The command associated with this file becomes invalid.

file makeDir [dir-name]

Make a directory.

Options

-permission

type: integer(Default 0755)

file remove [file-name]

Remove a file.

file removeDir [dir-name]

Remove a directory.

Example

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"
Comments