PackageTop Level
Classpublic class System

This class provides some system utility functions. Do not create an instance of this class - instead use the global system object.

See also

Global.system


Public Methods
 MethodDefined by
  
fileMatchesPattern(filePath:String, pattern:String):void
Returns true if the given file path matches the given pattern.
System
  
getDirectoryContents(directory:String, recursively:Boolean = false):void
Gets the list of files in the given directory.
System
  
killLockingProcesses(drive:String = null, safe:Boolean = true):void
Kills the applications that are locking (have an open handle on) the given drive.
System
  
resolvePath(filePath:String):void
Resolves a file path by converting "..", "." and special variables (such as $(Drive) or %windir%) to actual paths.
System
  
runCommand(commandLine:String, asynchronous:Boolean = false, functionName:String = ""):void
Allows running the given command line.
System
Method detail
fileMatchesPattern()method
public function fileMatchesPattern(filePath:String, pattern:String):void

Returns true if the given file path matches the given pattern.

Parameters
filePath:String — The path to a file
 
pattern:String — The pattern

Example
This script checks if a file path matches some patterns
  
 local filePath = "c:\temp\test.txt"  
 trace(system:fileMatchesPattern(filePath, "c:\temp\txt") -- displays "true"  
 trace(system:fileMatchesPattern(filePath, "c:\temp\t?st.txt") -- displays "true"  
 trace(system:fileMatchesPattern(filePath, "c:\temp\doc") -- displays "false"  
 

getDirectoryContents()method 
public function getDirectoryContents(directory:String, recursively:Boolean = false):void

Gets the list of files in the given directory.

Parameters
directory:String — The directory to retrieve the files from.
 
recursively:Boolean (default = false) — Set this to true to look for files into subfolders too
killLockingProcesses()method 
public function killLockingProcesses(drive:String = null, safe:Boolean = true):void

Kills the applications that are locking (have an open handle on) the given drive. If no drive is specified, the drive Appetizer is on will be used instead. The function has two modes: "safe" and "forced". In safe mode, the function tries to close the application windows properly, giving them a chance to save any settings or to display a message if changes need to be saved. The drawback is that some applications will not be closed. On the other hand, the "forced" mode is nearly guaranteed to close all the applications. In that case, the function will do two passes: one in "safe" mode where it tries to close the applications properly, and a second one where it kills the processes of the remaining applications (if any).

Parameters
drive:String (default = null) — Drive that needs to be unlocked.
 
safe:Boolean (default = true) — Sets this to true for the "safe" mode or false for the "forced" mode.
resolvePath()method 
public function resolvePath(filePath:String):void

Resolves a file path by converting "..", "." and special variables (such as $(Drive) or %windir%) to actual paths.

Parameters
filePath:String — The path to resolve
runCommand()method 
public function runCommand(commandLine:String, asynchronous:Boolean = false, functionName:String = ""):void

Allows running the given command line. It may be a full DOS command with arguments, or simply the path to an executable. The command can be run synchronously or asynchronously. If it runs synchronously, the function only returns when the command has been executed. In this case, it also returns the command line standard output. On the other hand, if the command is run asynchronously, the function returns immediately. You may then provide a callback function that will be called when the command has finished. The output can then be retrieved from the event.output property of the function parameter.

Parameters
commandLine:String — The command line to execute.
 
asynchronous:Boolean (default = false) — Sets this to true for asynchronous execution.
 
functionName:String (default = "") — Name of the callback function in asynchronous mode.

Example
This script calls a DOS command in synchronous mode.
  
 -- Running command in synchronous mode  
 result = system:runCommand('cmd /c "dir c: /On"')  
  
 -- The function returns the result when the command is complete.  
 dialogs:showMessage(result)  
 

This script calls a DOS command in asynchronous mode with callback.
  
 -- Define a function to retrieve the output  
 -- of the asynchronous command  
  
 function command_callback(event)  
     -- The output is in event.output  
     dialogs:showMessage(event.output)  
 end  
  
 -- Running command in asynchronous mode  
 system:runCommand('cmd /c "dir c: /On"', true, "command_callback")  
  
 -- Note that the function does not return anything in that case