Skip to content

System Object

Neo edited this page Jul 23, 2021 · 6 revisions

System

System object provides properties & functions for accessing the host filesystem and OS features to a certain extent.

Table of Contents


Properties

Property name Description
System.LocalTime Date object pointing to current time in local timezone
System.UtcTime Date object pointing to current time in UTC

Modifiers

The following functions modify the existence of a file/directory in 1 way or another.

Copy

Copies a file/directory to a target file/directory.

Syntax:

System.Copy(source, target, [force])
Argument Description
source The source path which we need to copy from.
target The destination path which we need to copy to.
force Optional boolean argument to enforce the copy process.

All the following combinations are valid for source & target.

Source Target What happens
file file If the target already exists then it will fail unless you are setting force as true.
file dir The source gets copied inside target directory. Same rules of force apply as above.
dir dir All the contents of the source directory gets copied inside target hierarchically and the same force setting is used in full hierarchy.

Returns: true if successfully copied else false.


Delete

Deletes a file/directory. Trying to delete a non-empty dir without force will cause the function to fail.

Syntax:

System.Delete(path, [force])
Argument Description
path The path to be deleted.
force Boolean argument to enforce the deletion process.
For directories, this means everything inside it will get deleted before the directory itself is deleted.

Returns: true if successfully deleted else false.


Trash

Moves a file/directory to the recycle bin.

Syntax:

System.Trash(path)
Argument Description
path The path to be trashed.

Returns: true if successfully trashed else false.


Move

Moves a file/directory to another path, essentially renaming it in the process.

Syntax:

System.Move(source, target)
Argument Description
source The source path which we need to move.
target The destination path.

All the following combinations are valid for source & target.

Source Target What happens
file file If the target already exists then it returns false.
file dir The source gets moved inside target directory unless it already has a file with the same name.
dir dir If the target already exists then the source gets moved inside the target directory.

Returns: true if successfully moved/renamed else false.


MkDir

Create the directory specified. Any missing parent directories are also created.

Syntax:

System.MkDir(path)
Argument Description
path The directory path to be created.

Returns: true if successfully done or if it already exists else false.


Name retrieval functions

All the following functions take a file path as argument and retrieve some part of it.

FileName

Retrieve the file name part of a path.

Syntax:

System.FileName(path)

BaseName

Retrieve the base name of a path (i.e. file name without suffix).

Syntax:

System.BaseName(path)

Suffix

Retrieve the suffix of a path.

Syntax:

System.Suffix(path)

DirName

Retrieve the parent directory name of a path.

Syntax:

System.DirName(path)

DirPath

Retrieve the parent directory path of the given file path.

Syntax:

System.DirPath(path)

FullPath

Retrieve the absolute full path of the given path after resolving any symlinks or relative paths.

Syntax:

System.FullPath(path)

Date retrieval functions

All the following functions retrieve a specific date information of a path which could be either a file or a directory.

CreatedDate

Retrieve the creation date of a file/directory.

Syntax:

System.CreatedDate(path)

ModifiedDate

Retrieve the last modified date of a file/directory.

Syntax:

System.ModifiedDate(path)

AccessedDate

Retrieve the last accessed date of a file/directory.

Syntax:

System.AccessedDate(path)

TouchedDate

Retrieve the last date when a file/directory was touched i.e. metadata was changed for e.g. when permissions change.

Syntax:

System.TouchedDate(path)

Directory listing functions

GetFiles

Get the list of files in a directory.

Syntax:

System.GetFiles(path, [filters])
Argument Description
path The directory path to be searched.
filters Optional Global patterns to restrict the list to matching names (similar to ls command). For e.g. "*.yaml".

Returns:

  • the matched list of files (all files if no filters provided) OR
  • empty list (if path is invalid or directory didn't have any matching files)

GetDirs

Get the list of sub directories in a directory.

Syntax:

System.GetDirs(path, [filters])
Argument Description
path The directory path to be searched.
filters Optional Global patterns to restrict the list to matching names (similar to ls command). For e.g. "*in".

Returns:

  • the matched list of sub-directories (all of them if no filters provided) OR
  • empty list (if path is invalid or directory didn't have any matching subdirs)

Testers

All of the following functions test for a specific status of a file/directory path.

Exists

Check for existence of a path in the filesystem.

Syntax:

System.Exists(path)

Returns: true or false .


IsFile

Check whether the path is an existing file or a symbolic link to one.

Syntax:

System.IsFile(path)

Returns: true or false .


IsDir

Check whether the path is an existing directory or a symbolic link to one.

Syntax:

System.IsDir(path)

Returns: true or false .


IsReadable

Check whether the path can be read from. Can be file or directory.

Syntax:

System.IsReadable(path)

Returns: true or false .


IsWritable

Check whether the path can be modified. Can be file or directory.

Syntax:

System.IsWritable(path)

Returns: true or false .


IsExecutable

Check whether the path has execution permission. Can be file or directory.

Syntax:

System.IsExecutable(path)

Returns: true or false .


IsHidden

Check whether the path is marked as hidden by the filesystem. Can be file or directory.

Syntax:

System.IsHidden(path)

Returns: true or false .


Miscellaneous

SizeOf

Retrieve the size of a file in bytes.

Syntax:

System.SizeOf(path)
Argument Description
path The file path (can be a symlink) whose size is needed.

Returns: the file's size or 0 if inaccesible / empty / not a file.


Return to top


Further reading