--- title: 'os' --- os provides a platform-independent interface to operating system functionality. ## Index * [def chdir(dir)](#def-iosibchdirb) * [def getenv(key) dir](#def-iosibgetenvb) * [def getwd() dir](#def-iosibgetwdb) * [def mkdir(name, perms=0o777)](#def-iosibmkdirb) * [def mkdir_all(name, perms=0o777)](#def-iosibmkdir_allb) * [def read_file(filename) string](#def-iosibread_fileb) * [def remove(name)](#def-iosibremoveb) * [def remove_all(path)](#def-iosibremove_allb) * [def rename(oldpath, newpath)](#def-iosibrenameb) * [def setenv(key, value) dir](#def-iosibsetenvb) * [def write_file(filename, data, perms=0o644)](#def-iosibwrite_fileb) ## Functions #### def os.chdir ```go os.chdir(dir) ``` changes the current working directory to the named directory. ###### Arguments | name | type | description | |------|------|-------------| | `dir` | `string` | target dir | #### def os.getenv ```go os.getenv(key) dir ``` retrieves the value of the environment variable named by the key. ###### Arguments | name | type | description | |------|------|-------------| | `key` | `string` | name of the environment variable | #### def os.getwd ```go os.getwd() dir ``` returns a rooted path name corresponding to the current directory. #### def os.mkdir ```go os.mkdir(name, perms=0o777) ``` creates a new directory with the specified name and permission bits (before umask). ###### Arguments | name | type | description | |------|------|-------------| | `name` | `string` | name of the folder to be created | | `perms` | `int` | optional, permission of the folder | #### def os.mkdir_all ```go os.mkdir_all(name, perms=0o777) ``` creates a new directory with the specified name and permission bits (before umask). ###### Arguments | name | type | description | |------|------|-------------| | `name` | `string` | name of the folder to be created | | `perms` | `int` | optional, permission of the folder | #### def os.read_file ```go os.read_file(filename) string ``` reads the file named by filename and returns the contents. ###### Arguments | name | type | description | |------|------|-------------| | `filename` | `string` | name of the file to be written | | `data` | `string` | content to be witten to the file | | `perms` | `int` | optional, permission of the file | #### def os.remove ```go os.remove(name) ``` removes the named file or (empty) directory. ###### Arguments | name | type | description | |------|------|-------------| | `name` | `string` | name of the file or directory to be deleted | #### def os.remove_all ```go os.remove_all(path) ``` removes path and any children it contains. It removes everything it can but returns the first error it encounters. ###### Arguments | name | type | description | |------|------|-------------| | `name` | `string` | path to be deleted | #### def os.rename ```go os.rename(oldpath, newpath) ``` renames (moves) oldpath to newpath. If newpath already exists and is not a directory, Rename replaces it. OS-specific restrictions may apply when oldpath and newpath are in different directories. ###### Arguments | name | type | description | |------|------|-------------| | `oldpath` | `string` | old path | | `newpath` | `string` | new path | #### def os.setenv ```go os.setenv(key, value) dir ``` sets the value of the environment variable named by the key. ###### Arguments | name | type | description | |------|------|-------------| | `key` | `string` | name of the environment variable | | `value` | `string` | value of the environment variable | #### def os.write_file ```go os.write_file(filename, data, perms=0o644) ``` retrieves the value of the environment variable named by the key. ###### Arguments | name | type | description | |------|------|-------------| | `filename` | `string` | name of the file to be written | | `data` | `string` | content to be witten to the file | | `perms` | `int` | optional, permission of the file |