-
-
Notifications
You must be signed in to change notification settings - Fork 55
System Object
System object provides properties & functions for accessing the host filesystem and OS features to a certain extent.
- Properties
- Modifiers
- Name retrieval functions
- Date retrieval functions
- Directory listing functions
- Testers
- Miscellaneous
Property name | Description |
---|---|
System.LocalTime | Date object pointing to current time in local timezone |
System.UtcTime | Date object pointing to current time in UTC |
The following functions modify the existence of a file/directory in 1 way or another.
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 elsefalse
.
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 elsefalse
.
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 elsefalse
.
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 elsefalse
.
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 elsefalse
.
All the following functions take a file path
as argument and retrieve some part of it.
Retrieve the file name part of a path.
Syntax:
System.FileName(path)
Retrieve the base name of a path (i.e. file name without suffix).
Syntax:
System.BaseName(path)
Retrieve the suffix of a path.
Syntax:
System.Suffix(path)
Retrieve the parent directory name of a path.
Syntax:
System.DirName(path)
Retrieve the parent directory path of the given file path.
Syntax:
System.DirPath(path)
Retrieve the absolute full path of the given path after resolving any symlinks or relative paths.
Syntax:
System.FullPath(path)
All the following functions retrieve a specific date information of a path
which could be either a file or a directory.
Retrieve the creation date of a file/directory.
Syntax:
System.CreatedDate(path)
Retrieve the last modified date of a file/directory.
Syntax:
System.ModifiedDate(path)
Retrieve the last accessed date of a file/directory.
Syntax:
System.AccessedDate(path)
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)
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)
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)
All of the following functions test for a specific status of a file/directory path
.
Check for existence of a path in the filesystem.
Syntax:
System.Exists(path)
Returns:
true
orfalse
.
Check whether the path is an existing file or a symbolic link to one.
Syntax:
System.IsFile(path)
Returns:
true
orfalse
.
Check whether the path is an existing directory or a symbolic link to one.
Syntax:
System.IsDir(path)
Returns:
true
orfalse
.
Check whether the path can be read from. Can be file or directory.
Syntax:
System.IsReadable(path)
Returns:
true
orfalse
.
Check whether the path can be modified. Can be file or directory.
Syntax:
System.IsWritable(path)
Returns:
true
orfalse
.
Check whether the path has execution permission. Can be file or directory.
Syntax:
System.IsExecutable(path)
Returns:
true
orfalse
.
Check whether the path is marked as hidden by the filesystem. Can be file or directory.
Syntax:
System.IsHidden(path)
Returns:
true
orfalse
.
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.