Functions - file

copy

Copy file/directory in old path to new path. If new path already exists, this replaces the file.

createDir

Creates a new directory with the specified file name. If parentDirs flag is true, Creates a directory in specified path with any necessary parents.

createFile

Creates a file in specified file path. Truncates if file already exists in the given path.

exists

Reports whether file or directory exists for the given the path.

getCurrentDirectory

Returns the current working directory.

getFileInfo

Returns metadata information of the file specified in file path.

readDir

Reads the directory and returns a list of files and directories # inside the specified directory

remove

Removes the specified file or directory. If recursive flag is true, Removes the path and any children it contains.

rename

Renames(Moves) old path to new path. If new path already exists and it is not a directory, this replaces the file.

tempDir

Returns the default directory to use for temporary files.

copy

(string sourcePath, string destinationPath, boolean replaceExisting)

returns Error?

Copy file/directory in old path to new path. If new path already exists, this replaces the file.

Parameters

  • sourcePath string
  • String value of old file path.

  • destinationPath string
  • String value of new file path.

  • replaceExisting boolean - false
  • Flag to allow replace if file already exists in destination path.

  • Return Type

    (Error?)
  • Returns an Error if failed to rename.

createDir

(string dir, boolean parentDirs)

returns string | Error

Creates a new directory with the specified file name. If parentDirs flag is true, Creates a directory in specified path with any necessary parents.

Parameters

  • dir string
  • directory name.

  • parentDirs boolean - false
  • Indicates whether the createDir should create non-existing parent directories.

  • Return Type

    (string | Error)
  • Returns absolute path value of the created directory or an Error if failed

createFile

(string path)

returns string | Error

Creates a file in specified file path. Truncates if file already exists in the given path.

Parameters

  • path string
  • String value of file path.

  • Return Type

    (string | Error)
  • Returns absolute path value of the created file or an Error if failed

exists

(string path)

returns boolean

Reports whether file or directory exists for the given the path.

Parameters

  • path string
  • String value of file path.

  • Return Type

    (boolean)
  • True if path is absolute, else false

getCurrentDirectory

()

returns string

Returns the current working directory.

  • Return Type

    (string)
  • Current working directory or an empty string if the current working directory cannot be determined

getFileInfo

(string path)

returns FileInfo | Error

Returns metadata information of the file specified in file path.

Parameters

  • path string
  • String value of the file path.

  • Return Type

    (FileInfo | Error)
  • Returns FileInfo instance with file metadata or an Error

readDir

(string path, int maxDepth)

returns FileInfo[] | Error

Reads the directory and returns a list of files and directories # inside the specified directory

Parameters

  • path string
  • String value of directory path.

  • maxDepth int - -1
  • The maximum number of directory levels to visit. -1 to indicate that all levels should be visited.

  • Return Type

    (FileInfo[] | Error)
  • Returns FileInfo array or an Error if there is an error while changing the mode.

remove

(string path, boolean recursive)

returns Error?

Removes the specified file or directory. If recursive flag is true, Removes the path and any children it contains.

Parameters

  • path string
  • String value of file/directory path.

  • recursive boolean - false
  • Indicates whether the remove should recursively remove all the file inside the given directory.

  • Return Type

    (Error?)
  • Returns an Error if failed to remove.

rename

(string oldPath, string newPath)

returns Error?

Renames(Moves) old path to new path. If new path already exists and it is not a directory, this replaces the file.

Parameters

  • oldPath string
  • String value of old file path.

  • newPath string
  • String value of new file path.

  • Return Type

    (Error?)
  • Returns an Error if failed to rename.

tempDir

()

returns string

Returns the default directory to use for temporary files.

  • Return Type

    (string)
  • Temporary directory location.