Functions -
file
copy |
Copy the file/directory in the old path to the new path.
|
createDir |
Creates a new directory with the specified file name.
|
createFile |
Creates a file in the specified file path.
|
exists |
Reports whether the file or directory exists in the given the path.
|
getCurrentDirectory |
Returns the current working directory.
|
getFileInfo |
Returns the metadata information of the file specified in the 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.
|
rename |
Renames(Moves) the old path with the new path.
|
tempDir |
Returns the default directory to use for temporary files.
|
Copy the file/directory in the old path to the new path. If a file already exists in the new path, this replaces that file.
file:Error? results = file:copy("/A/B/C", "/A/B/D", true);
Parameters
- sourcePath string
-
String value of the old file path
- destinationPath string
-
String value of the new file path
- replaceExisting boolean (default false)
-
Flag to replace if the file already exists in the destination path
-
Return Type
(Error?) An
file:Error
if failed to rename
Creates a new directory with the specified file name.
If the parentDirs
flag is true, it creates a directory in the specified path with any necessary parents.
string | error results = file:createDir("foo/bar");
Parameters
- dir string
-
Directory name
- parentDirs boolean (default false)
-
Indicates whether the
createDir
should create non-existing parent directories
-
Return Type
(string | Error) Absolute path value of the created directory or else an
file:Error
if failed
Creates a file in the specified file path. Truncates if the file already exists in the given path.
string | error results = file:createFile("bar.txt");
Parameters
- path string
-
String value of the file path
-
Return Type
(string | Error) Absolute path value of the created file or else an
file:Error
if failed
Reports whether the file or directory exists in the given the path.
boolean result = file:exists("foo/bar.txt");
Parameters
- path string
-
String value of the file path
-
Return Type
(boolean) True if the path is absolute or else false
Returns the current working directory.
string dirPath = file:getCurrentDirectory();
-
Return Type
(string) Current working directory or else an empty string if the current working directory cannot be determined
Returns the metadata information of the file specified in the file path.
file:FileInfo | error result = file:getFileInfo("foo/bar.txt");
Parameters
- path string
-
String value of the file path.
Reads the directory and returns a list of files and directories inside the specified directory.
file:FileInfo[] | error results = file:readDir("foo/bar");
Parameters
- path string
-
String value of the directory path.
- maxDepth int (default -1)
-
The maximum number of directory levels to visit. -1 to indicate that all levels should be visited
Removes the specified file or directory. If the recursive flag is true, it removes the path and any children it contains.
file:Error? results = file:remove("foo/bar.txt");
Parameters
- path string
-
String value of the file/directory path
- recursive boolean (default false)
-
Indicates whether the
remove
should recursively remove all the files inside the given directory
-
Return Type
(Error?) An
file:Error
if failed to remove
Renames(Moves) the old path with the new path. If the new path already exists and it is not a directory, this replaces the file.
file:error? results = file:rename("/A/B/C", "/A/B/D");
Parameters
- oldPath string
-
String value of the old file path
- newPath string
-
String value of the new file path
-
Return Type
(Error?) An
file:Error
if failed to rename