Python How To Get Current Directory
If you need to navigate the filesystem and you are probably going to want to be able to check where you are at some point. In Python it can be really handy to be able to get the current directory. We are going to show you how to do that.
To get the current directory using Python just import os and call os.getcwd() like this:
import os
os.getcwd()
You also might want be able to change what directory you are currently in. To do this on Linux, Unix, or Mac OS just use the following example.
os.chdir('/home/user1')
Here is an example of how you might do the same thing on Windows. Keep in mind that windows is going to use backslashes so you will probably want to escape them first.
os.chdir('C:\\Users\\user1')