# Find current directory and file's directory
To get the full path to the directory a Python file is contained in, write this in that file:
```python
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
```
(Note that the incantation above won't work if you've already used os.chdir() to change your current working directory, since the value of the __file__ constant is relative to the current working directory and is not changed by an os.chdir() call.)
---
To get the current working directory use
```python
import os
cwd = os.getcwd()
```
## Reference
- https://stackoverflow.com/questions/5137497/find-current-directory-and-files-directory