logo-MindMajix
PostPythonPython
k
kavya A

Posted on 19th July 2024|18 views

0
votes

Get All Files In Directory Python

How to list all the files of a directory in python?

1 answers
Answers
P
christina joce

Posted on 19th July 2024| views

You can use the glob module because it is capable of doing patter matching and expansion just like this

import glob 

print(glob.glob("/home/admin/*.txt"))

This will give you a list of queried files:

['/home/admin/file1.txt', '/home/admin/file2.txt', .... ]

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo

  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos
Name
Course *
Email *
Phone Number