The zos command provides platform dependent service functions.

zos configdir

Get the configuration directory.


Usage:

zos configdir ?-legacy?


Parameters:

-legacy (optional)

Get the legacy name of the config directory.


Example:

set config [zos configdir]

zos convertFilename

Convert paths and filenames from relative to absolute and vice versa.


Usage:

zos convertFilename filename mode ?dir?


Parameters:

dir (optional)

The conversion is relative to the given directory "dir" (dir must be absolute) or if dir is not given, then the conversion is relative to the current working directory.

filename

The file to convert.

mode

The convert mode.


Example:

# make an absolute filename relative to a given dir
# => my/file.txt
zos convertFilename "/my/path/my/file.txt" relative "/my/path"

# make a relative filename absolute
# => /my/test.txt
zos convertFilename "../test.txt" absolute "/my/path"

zos convertFilename2

Converts a given filename into relative-to-todir.


Usage:

zos convertFilename2 filename fromdir ?todir?


Parameters:

filename

The file to convert.

fromdir

The given filename is relative to the fromdir.

todir (optional)

The given filename is converted relative to the todir.


Example:

# => ../my/path/file.txt
zos convertFilename2 "demo/file.txt" "/my/path" "/other"

zos currentCputime

Can be used for cpu time measurement. The returned time value is in milliseconds. The option -ns can be used to return nanoseconds.


Usage:

zos currentCputime ?-ns?


Parameters:

-ns (optional)

Nanoseconds


Example:

set ns1 [zos currentCputime -ns]
# do some expensive work
set ns2 [zos currentCputime -ns]
set delta [expr {$ns2 - $ns1}]
puts "The expensive work took ${delta}ns CPU time."

zos currentLocalTime

Return the current time.


Usage:

zos currentLocalTime


Parameters:

No parameters.


Example:

set time [zos currentLocalTime]
set timeStr [clock format $time -format "%Y-%m-%d %T"]
puts $timeStr

zos currentLocalTimeString

Return the current time as a string.


Usage:

zos currentLocalTimeString


Parameters:

No parameters.


Example:

set timeStr [zos currentLocalTimeString]
puts $timeStr

zos currentRuntime

Can be used for runtime measurement. The returned time value is in milliseconds. The option -ns can be used to return nanoseconds.


Usage:

zos currentRuntime ?-ns?


Parameters:

-ns (optional)

Nanoseconds


Example:

set ms1 [zos currentRuntime]
# do some expensive work
set ms2 [zos currentRuntime]
set delta [expr {$ms2 - $ms1}]
puts "The expensive work took ${delta}ms wall clock time."

zos dirname

Return the directory name of the given filename.


Usage:

zos dirname filename


Parameters:

filename

The filename.


Example:

# => /my/path
zos dirname /my/path/file.txt

zos expandenv

Expand environment variables in the given string.

The variable names are terminated by any character other than "[A-z][0-9]_". But each name may be enclosed in '{}'. Dollar may be escaped by \\ - except on Windows.

Non-existing environment variables are replaced by the empty string.

On Windows only: '~' is replaced by $USERPROFILE.


Usage:

zos expandenv filename


Parameters:

filename

The path to a filename to expand environment variables.


Example:

# => /my/path/file.txt if the environment variable PROJECT_DIR is "/my/path"
zos expandenv "\${PROJECT_DIR}/file.txt"

zos filenametype

Return a number to indicate the type of the given path.

Possible values are: * -1: empty file name. * 0: file is absolute. * 1: file is relative * 2: file is volumerelative (Windows only) * 3: file is no volume absolute (Windows only)


Usage:

zos filenametype filename


Parameters:

filename

The filename.


Example:

# => 0 = absolute
zos filenametype /my/path/file.txt

# => 1 = relative
zos filenametype ../file.txt

zos homedir

Get the home directory.


Usage:

zos homedir ?user?


Parameters:

user (optional)

Get the homedir for this user.


Example:

set home [zos homedir]

zos numberOfProcessors

Return the number of processors.


Usage:

zos numberOfProcessors


Parameters:

No parameters.


Example:

set cpuCount [zos numberOfProcessors]

zos sanitizeFilename

Create a sanitized version of the given $filename, e.g. replace special characters (<, >, :, ", ', /, \\, |, ?, *) by _, avoid forbidden/special file names (., .., CON, PRN, AUX, NUL, COM1-9, LPT1-9, and variations thereof), etc. This function is useful when automatically creating file names from DB names, e.g.


Usage:

zos sanitizeFilename filename


Parameters:

filename

The filename to sanitize.


Example:

set name [$db oid oname $oid]
# $name may contain special characters; we need to sanitize it
set fileName [zos sanitizeFilename $name.txt]
set f [open $fileName w]

zos strcmpAlphanum

An alphanumeric string compare independent from any locale setting.


Usage:

zos strcmpAlphanum str1 str2


Parameters:

str1

The string to compare.

str2

The string to compare.


Example:

# => <0
zos strcmpAlphanum "A23" "A123"

# => >0
zos strcmpAlphanum "A42suffix" "A1other"

# => =0
zos strcmpAlphanum "Test123" "Test123"

zos tempdir

Return the path to temporary space.


Usage:

zos tempdir


Parameters:

No parameters.


Example:

set temp [zos tempdir]

zos tempFilename

Return the name of an unique temporary file.


Usage:

zos tempFilename prefix ?tempDir?


Parameters:

prefix

A prefix used to generate the temp filename.

tempDir (optional)

Path to a tmp directory.


Example:

# => something like /tmp/my_prefix_123456
zos tempFilename my_prefix

zos uniqueFileName

Make the given filename unique. Path can be relative or absolute. Removes extension (string after last .) and appends '_' and a number.


Usage:

zos uniqueFileName filename


Parameters:

filename

The filename to unify.


Example:

set filename [file join [zos tempdir] file.txt]
# => something like /tmp/file_123.txt if /tmp/file.txt already exists.
set unique [zos uniqueFileName $filename]