0

Trying to list, for example, all the jpgs on two drives. Single drive search looks like:

from pathlib import Path

for path in Path("/Volumes/MasterOne").rglob('*'):
    for file_name in path.glob('*.jpg'):   
        print(file_name)

But am not finding how to add a second volume to the for loop and iterate for files on both drives.

paths = ("/Volumes/MasterOne", "/Volumes/MasterTwo")
Woolwit
  • 89
  • 8

2 Answers2

1

You might add outer for to get desired behavior as follows

from pathlib import Path

for p in ("/Volumes/MasterOne", "/Volumes/MasterTwo"):
    for path in Path(p).rglob('*'):
        for file_name in path.glob('*.jpg'):   
            print(file_name)
Daweo
  • 31,313
  • 3
  • 12
  • 25
0

Try different type of loops! As if else and for loops pretty much helps around!

for p in ("/Volumes/MasterOne", "/Volumes/MasterTwo"):
    for path in Path(p).rglob('*'):
        for file_name in path.glob('*.jpg'):   
            print(file_name)
Reza Rahemtola
  • 1,182
  • 7
  • 16
  • 30
Dev Adnan
  • 1
  • 1