Functions involving the file system.
Methods
getFiles(filespec,recurse) |
Returns an array of strings, each string is the full filename of every file matching the given filespec string. An example filespec string would be c:\\myfolder\\*.jpg. Set 'recurse' to true to search all subfolders too. |
openRead(filename) |
Opens the given filename and returns a File object to access it. The File object uses properties/methods:- length, close(), readStringArray(), readByteArray(). Always call close() when you're finished with the file. |
openWrite(filename) |
Opens the given filename and returns a File object to access it. The File object uses properties/methods:- close(), writeStringArray(stringarray), writeByteArray(). Always call close() when you're finished with the file. If the filename contains a path that doesn't exist, the path will also be created. |
exists(filename) |
Returns true if the given file exists. |
delete(filename) |
Deletes the file and returns true if successful. |
rename(filename,newfilename) |
Returns true if the given file is renamed to the new filename. |
copy(filename,newfilename) |
Returns true if the given file is successfully copied to the new filename. |
move(filename,newfilename) |
Returns true if the given file is successfully moved to the new filename. |
openFileDialog(defaultFilename,filter,defaultExtension) |
Prompts the user to select an existing file and returns the full filename or null if cancelled. The defaultFilename property is a string that will direct the dialog folder and/or filename to an initial location. The filter is defined by a string delimited with | characters as shown below. The defaultExtension string is used to automatically append an extension, e.g. "PNG" would force a .PNG file to be returned. |
saveFileDialog(defaultFilename,filter,defaultExtension) |
Prompts the user to select a file to write to and returns the full filename or null if cancelled. The defaultFilename property is a string that will direct the dialog folder and/or filename to an initial location. The filter is defined by a string delimited with | characters as shown below. The defaultExtension string is used to automatically append an extension, e.g. "PNG" would force a .PNG file to be returned. |
partFilename(fullFilename) |
Extracts the filename without directory from a string filename. |
partDirectory(fullFilename) |
Extracts the directory from a string filename. |
partFilenameWithoutExtension(fullFilename) |
Extracts the filename without directory or extension from a string filename. |
partExtension(fullFilename) |
Extracts the file extension from a string filename. |
cacheRemoveAll() |
Removes all files from the internal file cache. |
Examples
function onInit()
{
var files = system.file.getFiles("c:\\myfolder\\*.jpg",true);
print("Found "+files.length+" files!");
for(var i=0;i<files.length;i++)
{
print("File "+i+": "+files[i]);
}
}
Remarks
The filter property of the file dialogs is based on the the Windows convention of delimiting a string with the | character.
<user displayed text of filter 1> | <filespec of what this selects> || <user displayed text of filter 2> | <filespec of what this selects> || etc...
Example filters are:-
var filter1="PNG Files|*.PNG||JPEG Files|*.JPG||";
var filter2="Funky files (*.dxfunky)|*.DXFUNKY||";
See Also


