在while循环中的某个点,我对一个包含三个项目的索引运行os.listdir以生成一个文件列表,并得到"Windows Error 3- Path get“,尽管我之前已经在脚本中成功地调用了这个路径。
之后,我对它运行了一个os.path.exists,它显示在前两个循环中,目录的计算结果为False,但在第三个循环中,它的计算结果为True。
我试过使用glob.glob,它也只在第三次循环时返回文件。
问题出在“基于找到的镜头数创建读取节点”注释下的while循环中。
如果能帮助我们从一开始就把它理解为True,我们将不胜感激,谢谢!
# Iterating using while loop, this gets every version folder for each shots' plates and stores to a "version" list
while shotIndex < shotAmountTotal:
nextShot = (shots[shotIndex])
shotIndex += 1
verSearchPath = shotSearchPath + '/' + nextShot + '/' + compFolder + '/' + platesFolder
foundVerList = os.listdir(verSearchPath)
verListCombined.append(foundVerList)
verListSorted = list(chain.from_iterable(verListCombined))
#this groups the like folder names, splits them at the underscore before the version number and then returns only the highest version number of each group
groupedShotFolders = groupby(verListSorted, key=lambda version: version.rsplit('_', 1)[0])
latestShotVer = [sorted(group, reverse=True)[0] for key, group in groupedShotFolders]
#creates Read nodes based on number of shots found
latestShotAmount = len(latestShotVer)
latestShotIndex = 0
while latestShotIndex < latestShotAmount:
latestShot = (latestShotVer[latestShotIndex])
frameListerPath = verSearchPath + '/' + latestShot + '/' + fileExtension + '/'
print os.path.exists(frameListerPath)
frameLister = os.listdir(verSearchPath + '/' + latestShot + '/' + fileExtension + '/')
我得到的终端输出是:
Result: False
E:/projects/MBR/shots/103/MRS_103_005_020/2d/plates/MRS_103_005_010_BG_001_v002/exr/
[]
False
E:/projects/MBR/shots/103/MRS_103_005_020/2d/plates/MRS_103_005_010_FG_001_v003/exr/
[]
True
E:/projects/MBR/shots/103/MRS_103_005_020/2d/plates/MRS_103_005_020_BG_001_v003/exr/
['E:/projects/MBR/shots/103/MRS_103_005_020/2d/plates/MRS_103_005_020_BG_001_v003/exr\\MRS_103_005_020_BG_001_v003.0999.exr', 'E:/projects/MBR/shots/103/MRS_103_005_020/2d/plates/MRS_103_005_020_BG_001_v003/exr\\MRS_103_005_020_BG_001_v003.1000.exr', 'E:/projects/MBR/shots/103/MRS_103_005_020/2d/plates/MRS_103_005_020_BG_001_v003/exr\\MRS_103_005_020_BG_001_v003.1001.exr', 'E:/projects/MBR/shots/103/MRS_103_005_020/2d/plates/MRS_103_005_020_BG_001_v003/exr\\MRS_103_005_020_BG_001_v003.1002.exr']
发布于 2019-05-14 13:29:42
好吧,我会把这个问题归结为用户错误。首先,我切换到"for“和"join”方法来清理一些东西。接下来,我发现前面代码中的"nextShot“变量没有正确迭代,因此它只输出迭代的最后一项,这就是为什么前两个路径的计算结果为False。我通过将"latestShot“变量放在它的位置并修剪掉描述符来修复这个问题。
为了避免使用"os.listdir“时出现的双斜杠,我将其拆分并使用正斜杠重新连接。
感谢您对此的思考和指导。
for latestShot in latestShotVer:
nuke.createNode("Read", inpanel = False)
frameListerPath = os.path.join(shotSearchPath, latestShot[:-12], compFolder, platesFolder, latestShot, fileExtension)
flsplit = frameListerPath.split('\\')
fljoin = '/'.join(flsplit)
frameListerPath = fljoin
frameLister = os.listdir(frameListerPath)
https://stackoverflow.com/questions/56117793
复制相似问题