我有一个python应用程序,它应该将OSX上的.app复制到一个新的地方,然后运行它。我在复制之前和之后对文件执行SHA1校验和,以确保复制没有错误,并且校验和已签出。有人能想到为什么会这样吗?我还确保文件权限在复制的.app上完全打开chmod 777,但没有修复它。你知道吗
这是python中copy函数的核心。这是从其他地方提取的一个稍微编辑过的:
def copy_directory_recursive(self, srcPath, dstPath):
dirAndFileList = os.listdir(srcPath)
dirList = []
fileList = []
for i in dirAndFileList:
if os.path.isdir(os.path.join(srcPath, i)):
dirList.append(i)
elif os.path.isfile(os.path.join(srcPath, i)):
fileList.append(i)
dirList.sort()
fileList.sort()
for directory in dirList:
# if qItem.HasCancelled(): #If user has cancelled the copy, quit
# break
os.mkdir(os.path.join(dstPath, directory))
newSrc = os.path.join(srcPath, directory)
newDst = os.path.join(dstPath, directory)
# Call itself to do move into the newly created subfolder and
# repeat...
self.copy_directory_recursive(newSrc, newDst)
for file in fileList:
# if qItem.HasCancelled(): #If user has cancelled the copy, quit
# break
# Copy the file
shutil.copyfile(
os.path.join(srcPath, file), os.path.join(dstPath, file))
self.filesCopied += 1
# Feedback to the progress bar of the queue Item
self.update()
您可以使用来自
shutils
的copytree
调用来更新进度。举个例子:相关问题 更多 >
编程相关推荐