Class FileSystem

This class contains filesystem specific methods.

File Paths

The paths may have "/" or "\" as separator characters. These are converted to separator characters that are supported by the native filesystem. If the path has several adjoining separators, these are combined to one separator.

Wildcards or references to parent directory using ".." are not supported

Resource Files

Resource files are copied from the project's "Resource Files" directory to the installation package. These files can be accessed using pathnames relative to the Resource Files directory. The filename may have optional separator character at the beginning of the filename.

Methods


(bool) file exists <string filename>

Check file's existence.

Parameters

Return value

Example

main
  bool fileExists = filesystem.file exists "image.png"

  if ( fileExists )
    print "File found."
  else
    print "File not found."
                

(bool) directory exists <string directoryname>

Check directory's existence.

Parameters

Return value

Example

main
  bool dirExists = filesystem.directory exists "images\"

  if ( dirExists )
    print "Directory found."
  else
    print "directory not found."
                

remove file <string filename>

Removes a file.

Parameters

Exceptions

Example

main
  try
    filesystem.remove file "images\image.png"
  catch IOException e
    print "File could not be removed"
    return

  print "File removed."
                

remove directory <string directoryName>

Removes a directory.

Parameters

Exceptions

Example

main
  try
    filesystem.remove directory "images\"
  catch IOException e
    print "Directory could not be removed."
    return

  print "Directory removed."
                

(string) list directories from <string path>

Lists all sub-directories of the specified directory.

Parameters

Return value

Exceptions

Example

main
  String[] directories
  try
    directories = filesystem.list directories from "images\"
  catch IOException e
    print "Directories could not be listed."
    return

  print "Directory listing:"
  i = 0
  while ( i < directories.get size )
    print directories[i]
    i++
                

(string) list files from <string path>

Lists all files of the specified directory.

Parameters

Return value

Exceptions

Example

main
  String[] files
  try
    files = filesystem.list files from "images\"
  catch IOException e
    print "Files could not be listed."
    return

  print "File listing:"
  i = 0
  while ( i < files.get size )
    print files[i]
    i++
                

create file <string filename>

Creates a file. The file content is truncated if the file already exists.

Parameters

Exceptions

Example

main
  try
    filesystem.create file "images\picture.jpg"
  catch IOException e
    print "File could not be created."
    return

  print "File created."
                

create directory <string path>

Creates a directory if does not exist.

Parameters

Exceptions

Example

main
  try
    filesystem.create directory "images\newImages\"
  catch IOException e
    print "Directory could not be created."
    return

  print "Directory created."
                

move file <string fromPath> to <string toPath>

Moves a file from fromPath to toPath.

Parameters

Exceptions

Example

main
  try
    filesystem.move file "image.png" to "images\newImages\"
  catch IOException e
    print "File could not be moved."
    return

  print "File move successful."
                

move directory <string fromPath> to <string toPath>

Moves a directory from fromPath to toPath. Note that the target directory should not exist beforehand. If you want to move the the directory to the already existing directory you should specify a non existing sub-directory for it.

Parameters

Exceptions

Example

main
  try
    filesystem.move directory "tempImages\" to "images\newImages\"
  catch IOException e
    print "Directory could not be moved."
    return

  print "Directory moved successfully."