Os
Contains common operations for Os & System related functionality.
Functions
All the current functions of the Os module.
exit(code: number)
Directly exit the script with the given code argument.
Os.exit(0); //success
remove(path: string)
Deletes a file specified by the path argument. Returns 0 on success otherwise -1 on failure.
Os.remove("some/real/file.txt"); //0
getHome()
Returns the home location of the user's system as a string.
Os.getHome(); //C:\Users\Someone
getCwd()
Returns the current working directory as a string. Otherwise -1 incase of failure.
Os.getCwd();
// *Inserts current working directory*
setCwd(path: string)
Sets the current working directory to the path argument. Returns -1 incase of failure otherwise 0.
Os.setCwd("some/other/directory"); //0
mkdir(path: string, mode?: number )
Makes a directory specified by the path argument along a number argument that specifies the mode, by default it's 0777.
Returns 0 on success otherwise -1 on failure.
Os.mkdir("some/real/directory"); //0
rmdir(path: string)
Removes a directory. Returns 0 on success otherwise -1 on failure.
Os.rmdir("some/fake/directory.txt"); //-1
makeDirs(path: string)
Makes nested directories according to the path argument with the mode 0777.
Os.makeDirs("some/directory1/directory2");
//0
Properties
All the current properties of the os module.
File permissions
Different properties to check for the different permissions of a file.
Os.F_OK // test for file existence
Os.X_OK // test for execution permission
Os.W_OK // test for write permission
Os.R_OK // test for read permission
Platform name
Returns a string representing the platform name that the script is running on.
Os.name; //Windows 32
Failure & Success codes
Represents 2 exit codes. One used to indicate program success and the other to indicate failure.
Os.EXIT_FAILURE; //1
Os.EXIT_SUCCESS; //0