Python File System Operation Snippets Collection
In this post, I’ll share some simple snippet to do various file system operation. Pretty much as a bookmark for my own usage, in case I needed it someday.
How to get current working directory:
import os
os.getcwd()
How to change working directory:
import os
os.chdir(‘/tmp/’)
How to list directory contents:
import os
os.listdir(‘/tmp/’)
How to check if directory / file exists:
import os
os.path.exists(‘/tmp/’)#work for both [...]



