0

I can list certain files but my code has problems that it only can list files in C:\

I want to change the code so I can scan other drives (for example: drive D, E, F & ...)

How can i do this

Please check my code first and then respond to my question to know what I mean

My code:

import os

def discoverFiles(start):
    extensions = [
        'pdf','mp3','mp4','txt','docx'
    ]

    for dirpath, dirs, files in os.walk(start):
        for i in files:
            absolute_path = os.path.abspath(os.path.join(dirpath, i))
            ext = absolute_path.split('.')[-1]
            if ext in extensions:
                yield absolute_path

x = discoverFiles('/')
for j in x:
    print (j)

MR_Alex
  • 11
  • 2
  • You might be interested in https://stackoverflow.com/questions/827371/is-there-a-way-to-list-all-the-available-drive-letters-in-python – Dan D. Dec 26 '18 at 04:59
  • It might be possible to use the NT namespace (`\\?\…`) to find a directory above the drives, but I don’t know where they might be in it. – Davis Herring Dec 26 '18 at 17:00

1 Answers1

0

You can list file in other drives like this

x = discoverFiles(r'D:\\')
Ha Bom
  • 2,787
  • 3
  • 15
  • 29