Get the current Directory in Python

Introduction:

A directory is a file system cataloging structure that contains references to other computer files, and possibly other directories. On many computers, directories are known as folders.



Get the current Directory in Python

In order to get and change the current working directory, we will use a python Lib called “os”.

This module provides a portable way of using operating system-dependent functionality. it’s independent of the type of the operating system (Linux, Windows, Mac …)



One of the functions of the OS module is getcwd(), which we will use to get the current working directory.

os.getcwd(): Return a string representing the current working directory.

import os

print(os.getcwd())

See: change the working directory in Python

https://en.wikipedia.org/wiki/Directory_(computing)


Bilel

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x