File Commands

From Bohemia Interactive Community
Jump to navigation Jump to search


see [[File Commands]setcd]


_folder=GetCD; // returns fully qualified (P:\etc)


   Opens stream for standard input and output. If no standard I/O is assigned, creates console, and redirect I/O into console. Note: Always assign result to variable, and access stream with variable.


   console=openStandardIO; console<<"Hallo world"

console=nil; close it

openFile ["filename",mode]

  • Returns IOStream

Opens or creates a file specified by filename. Mode contain one of following values:

  • 0 - test existence of file (no open)
  • 1 - open existing file for reading
  • 2 - create new file for writting
  • 3 - open existing file for reading and writting
  • 4 - open (create if not exists) file for reading and writting


_file=openFile ["some\file\anywhere.ext",0];
if (!isnil("_file")) then {do_something;_file=nil;};

Note: _file will be non nil for mode 0

shellCmd "command"

Retursn: Result (number)

Function waits until command is finished

result is -1 if file not found, or cannot be started, otherwise returns application's exit code


   _result = shellCmd ("notepad.exe");

shellCmdOpenPipe "command"

Returns IOStream

Creates bi-directional pipe to the new process. Script can use this pipe to send commands to child process and read its results


_files=shellCmdOpenPipe ("dir /b/a:-d-h/L *.p3d"); list only p3d files in lower case, no hidden stuff
while "!eof _files" do 
 _filename= getline _files;
 if (_filename!="") then {[_filename] call something;};

SplitPath "Path"

Returns the Path string into a 4 element array



   splitPath "C:\test\anywhere\anyFile.txt" , result is ["c:","\test\anywhere","anyFile",".txt"]

this command does not work as nature intended

the drive is force-set to current drive

the folder path is determined by current directory

a lack of preceding slash adds it. any drive specification in the string (such as proxy:) is treated as folder path (part of)