我想对文件列表应用测试。通过测试的文件应移到“Pass”目录下;其他文件应移到“Fail”目录下。你知道吗
因此,输出目录应该包含子目录“Pass”和“Fail”。你知道吗
以下是我的尝试:
if(<scan==pass>) # Working fine up to this point
dest_dir = outDir + '\\' + 'Pass' # The problem is here
print("Pass", xmlfile)
MoveFileToDirectory(inDir, xmlfile, dest_dir)
else:
dest_dir = os.path.dirname(outDir + '\\' + 'Fail')
print("Fail: ", xmlfile)
MoveFileToDirectory(inDir, xmlfile, dest_dir)
但是,我的代码是将文件移动到输出目录,而不是创建“Pass”或“Fail”子目录。知道为什么吗?你知道吗
使用操作系统路径连接(). 示例:
See this SO post
而且,我们不知道
MoveFileToDirectory
做什么。使用标准os.rename
:See this SO post
所以:
只创建一次目录:
然后可以将文件移动到创建的目录中:
代码利用了Python中的
False == 0
和True == 1
。你知道吗相关问题 更多 >
编程相关推荐