Deal With Python Directory | What Is Python Directory- Python Tutorial Help

Updated: Mar 19

What is Directory in Python?

A directory or folder is a collection of files and sub directories. Python has the os module. which provides us with many useful methods to work with directories (and files as well).

Get Current Directory

Use command :



>>> import module



'C:\\Program Files\\Py...'

Use print() to escape extra backspace.


>>> print(os.getcwd())


C:\Program Files\PyScripter

Changing Directory

We can change the current working directory using the chdir() method.


>>> os.chdir('C:\\Python33')

>>> print(os.getcwd())



List Directories and Files

Use method:



>>> os.listdir()


['DLLs','Doc','include','Lib','libs',... ]

Create New Directory

Use method

>>> os.mkdir('test')

Renaming a Directory or a File

The rename() method can rename a directory or a file.

>>> os.listdir()



>>> os.rename('test','new') #rename "test" into "new"

Removing Directory or File

A file can be removed (deleted) using the remove() method.

rmdir() used to remove empty directory.


>>> os.remove('file.txt')

Hope you understand the all the concept of file or directory.

If you like Codersarts blog and looking for Assignment help,Project help, Programming tutors help and suggestion  you can send mail at

Please write your suggestion in comment section below if you find anything incorrect in this blog post.

#python #pythonassignmenthelp #pythonassignmenthelp #pythonfileanddirectory

Contact Us

Tel: (+91) 0120  4118730  

Time :   10 : 00  AM -  08 : 00 PM IST 

Registered address: G-69, Sector 63, 

 Noida - 201301, India

We Provide Services Across The different countries

USA    Australia   Canada   UK    UAE    Singapore   New Zealand    Malasia   India   Ireland   Germany

Terms and Conditions        Privacy Policy    Pricing Policy       Refund Policy         COPYRIGHT © 2021

Sofstack Technology Solutions Pvt. Ltd.

  • CodersArts | Linkedin
  • Instagram