Tutorial by Examples

os.mkdir('newdir') If you need to specify permissions, you can use the optional mode argument: os.mkdir('newdir', mode=0700)
Use the os.getcwd() function: print(os.getcwd())
The os module provides an interface to determine what type of operating system the code is currently running on. os.name This can return one of the following in Python 3: posix nt ce java More detailed information can be retrieved from sys.platform
Remove the directory at path: os.rmdir(path) You should not use os.remove() to remove a directory. That function is for files and using it on directories will result in an OSError
Sometimes you need to determine the target of a symlink. os.readlink will do this: print(os.readlink(path_to_symlink))
os.chmod(path, mode) where mode is the desired permission, in octal.
Given a local directory with the following contents: └── dir1 ├── subdir1 └── subdir2 We want to create the same subdir1, subdir2 under a new directory dir2, which does not exist yet. import os os.makedirs("./dir2/subdir1") os.makedirs("./dir2/subdir2") R...

Page 1 of 1