0

Below is my attached code.

def getListOfFiles(dirName):
  import os
  # create a list of file and sub directories 
  # names in the given directory
  listOfFile = os.listdir(dirName)
  allFiles = list()
  # Iterate over all the entries
  for entry in listOfFile:
    # Create full path
    fullPath = os.path.join(dirName, entry)
    # If entry is a directory then get the list of files in this directory 
    if os.path.isdir(fullPath):
        allFiles = allFiles + getListOfFiles(fullPath)
    else:
        if fullPath.endswith('jpg'):
            allFiles.append(fullPath)
        elif fullPath.endswith('jpeg'):
            allFiles.append(fullPath)
        elif fullPath.endswith('png'):
            allFiles.append(fullPath)
        elif fullPath.endswith('JPG'):
            allFiles.append(fullPath)
return allFiles

What I have is a folder with a lot of organised photos in subdirectories. This code is used to return a paths to all those photos, where a random path is then chosen to copy into another folder for home-assistant to create a type of slideshow.

Now the problem is, that Synology (where this is running) creates thumbnails for all the pictures in a subdirectory called @eaDir for each photo. For example:

/Slideshow/2018/Flytning_Cody/@eaDir/IMG_0364.JPG/SYNOPHOTO_THUMB_XL.jpg

What I want, is only to have the IM_0364.JPG path return (for every image, including .png, .jpeg). These files have a path at:

/Slideshow/2018/Flytning_Cody/IMG_0015.JPG

How can I make the code skip pass everything in a directory named @eaDir (which are created at many sub levels)?

I've tried using glob.glob() and glob.iglob() but without much luck (suspect user error)

GKH
  • 179
  • 1
  • 13
  • 1
    run code in `if "@" not in fullPath: ...` – furas Nov 03 '21 at 14:30
  • 1
    you can use tuple in `fullPath.endswith( ('jpg', 'jpeg', 'JPG', 'png', 'PNG') ):` and to make it shorter you can use `lower()` (or `upper()`) and then you don't have to check `JPG`, `PNG` - `fullPath.lower().endswith( ('jpg', 'jpeg', 'png') ):` – furas Nov 03 '21 at 14:33

0 Answers0