Python program to get the current working directory:
In this post, I will show you how to get the current working directory in Python. Python os module provides different methods for different operating system related functions. Current working directory is the directory where the program is currently working on.
Python os.getcwd():
getcwd() method is used to get the current working directory. This method is defined in the os module. It is defined as below:
os.getcwd()
It returnes the current working directory as a string.
To use this method, we need to import os module.
Example program:
import os
print('Current working directory: {}'.format(os.getcwd()))
If you run this program, it will print the current working directory. If you are running this program in a python file, it will print the directory where the file exists.
You might also like:
- How to get the last access time of a path in python
- Python program to get the last modified time of a path
- How to find the common path in a list of paths in python
- Python program to get the absolute path of a file
- How to get the directory name of a given path in Python
- Python program to change the current working directory