0

下面是我附加的代码。

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

我拥有的是一个文件夹,其中有很多子目录中有组织的照片。此代码用于返回所有这些照片的路径,然后选择随机路径复制到另一个文件夹中,以便家庭助理创建一种幻灯片。

现在的问题是,Synology(运行它的地方)@eaDir为每张照片调用的子目录中的所有图片创建缩略图。例如:

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

我想要的只是返回 IM_0364.JPG 路径(对于每个图像,包括 .png、.jpeg)。这些文件的路径位于:

/Slideshow/2018/Flytning_Cody/IMG_0015.JPG

如何使代码跳过传递名为@eaDir(在许多子级别创建的)目录中的所有内容?

我尝试过使用glob.glob()glob.iglob()但运气不佳(怀疑用户错误)

4

0 回答 0