Hamster-Scripts: Functions (built-in)

Files and directories

execute( <cmdline>, <workdir>, <show>, <wait>, <exitcode> )

Starts the program given in <cmdline>, which also can contain parameters and options needed by this program.

If <workdir> is given, it is set as the workding-directory for the started program.

<show> controls, how the started program is shown (0=hidden, 1=default=normal, 2=minimized, 3=maximized). Please note, that there will be no visible window, if HService itself is running invisible as a service, regardless which value you choose for <show>.

If <wait> is set to true (default), execution of the script is paused until the started program has finished.

If the exit-code of the program is needed, it can be saved in the variable <exitcode>.

Returns: Integer (0=no error, <>0=error)

execute( "notepad.exe myfile.cfg" )

IniRead( <filename>, <section>, <ident>, <default> )

Reads an entry from the .INI-file named <filename>. If no <filename> is given, file "HScripts.ini" is used. If no <section> is given, section "[All]" is used.

If "[<section>]" does not contain an entry named "<ident>=...", the value <default> is returned.

Returns: String

$answer = IniRead( "MyScript.ini", "Answers", "Last", "42")
$LastConnected = int( IniRead( "", "", "LastConnected", 0 ) )

IniWrite( <filename>, <section>, <ident>, <value> )

Writes an entry to the .INI-file named <filename>. If no <filename> is given, file "HScripts.ini" is used. If no <section> is given, section "[All]" is used.

Returns: 0: OK, <>0: Error

IniWrite( "MyScript.ini", "Answers", "Last", $answer )
IniWrite( "", "", "LastConnected", time )

FileExists( <filename> )

Checks, if the given file exists. <filename> may contain wildcards "?" and "*".

Returns: Integer (1=exists, 0=doesn't exist or invalid filename/path)

if( !fileexists("myfile.cfg" ) )
   error( "Missing configuration file!" )
endif

FileSize( <filename> )

Returns size of file <filename>.

Returns: Integer (-1 if file is missing)

print( FileSize( HamPath + "Hamster.exe" ) )

FileTime( <filename> )

Returns time of last update of file <filename>.

Returns: Integer (-1 if file is missing)

print( "Your Hamster's age: ", time - FileTime( HamPath + "Hamster.exe" ), " seconds" )

FileDelete( <filename> )

Deletes the file named <filename> (wildcards "*" and "?" are supported).

Returns: 0: OK, <>0: Error

FileDelete( "MyScript.tmp" )
FileDelete( "*.bak" )

FileRename( <oldname>, <newname> )

Renames the file named <oldname> to <newname>.

Returns: 0: OK, <>0: Error

FileRename( "MyScript.dat", "MyScript.bak" )

FileCopy( <oldname>, <newname> )

Copies the file named <oldname> to <newname>.

If <oldname> contains wildcards ("*" and "?"), parameter <newname> has to be an existing directory.

Returns: 0: OK, <>0: Error

FileCopy( "MyScript.dat", "MyScript.bak" )
FileCopy( "*.msg", "c:\backup\" )

FileMove( <oldname>, <newname> )

Moves the file named <oldname> to <newname>, i. e. copy <oldname> to <newname> and then delete <oldname>.

If <oldname> contains wildcards ("*" and "?"), parameter <newname> has to be an existing directory.

Returns: 0: OK, <>0: Error

FileMove( "*.log", "c:\temp" )

DirExists( <dirname> )

Checks, if the given directory exists.

Returns: Integer (1=exists, 0=doesn't exist or invalid path)

if( !direxists( "mydir" ) )
   # ...
endif

DirMake( <dirname> )

Creates a new directory named <dirname>.

Returns: 0: OK, <>0: Error

DirMake( HamPath + "MyScript" )

DirRemove( <dirname> )

Removes the directory named <dirname>, if it is empty.

Returns: 0: OK, <>0: Error

DirRemove( HamPath + "MyScript" )

DirChange( <dirname> )

Makes the directory named <dirname> the current directory.

NOTE: Not suggested, use full qualified filenames instead.

Returns: 0: OK, <>0: Error

DirChange( HamPath + "MyScript" )

DirCurrent

Returns the name of the current directory. The name is always returned with a trailing backslash.

Returns: 0: OK, <>0: Error

print( DirCurrent )

DirWindows

Returns the name of the Windows directory. The name is always returned with a trailing backslash.

Returns: 0: OK, <>0: Error

print( DirWindows )

DirSystem

Returns the name of the Windows system directory. The name is always returned with a trailing backslash.

Returns: 0: OK, <>0: Error

print( DirSystem )

DiskInfo( <type>, <drive-letter> )

DiskInfo( <type> )

Returns information about a disk drive, either free space (<type>=0) or total size (<type>=1).
If <drive-letter> is omitted, current drive is used.

Note: Due to limitation of script's integer range, returned info is in kilobyte (1 KB = 1024 Byte).

Returns: >=0: Result, <0: Error

print( DiskInfo(0,"C"), " of ", DiskInfo(1,"C"), " KB free on drive C:" )

See also: ListLoad, ListSave, ListFiles, ListDirs.

 

[www.elbiah.de Hamster Playground Documentation]