我试图在python中移动一些文件,但是它们的名称中有空格。有没有什么方法可以明确地告诉python将字符串作为文件名来处理?在
listing = os.listdir(self.Parent.userTempFolderPath)
for infile in listing:
if infile.find("Thumbs.db") == -1 and infile.find("DS") == -1:
fileMover.moveFile(infile, self.Parent.userTempFolderPath, self.Parent.currentProjectObject.Watchfolder, True)
在我从清单中得到文件后,我对它运行os.path.exists
,看看它是否存在,它永远不存在!有人能给我个提示吗?在
文件名中的空格不是问题;
os.listdir
返回文件名,而不是完整路径。在您需要将它们添加到您的文件名中以测试它们;^{} 将使用适合您平台的正确目录分隔符为您执行此操作:
注意,我还简化了文件名测试;我没有使用
.find(..) == -1
,而是使用了not in
运算符。在相关问题 更多 >
编程相关推荐