0
votes

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)

1
You might be interested in stackoverflow.com/questions/827371/… - Dan D.
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

1 Answers

0
votes

You can list file in other drives like this

x = discoverFiles(r'D:\\')