- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在编写一个Python脚本,当我尝试使用扩展列表作为copytree的ignore_patterns时,该脚本会抛出TypeError: unhashable type: 'list'。我不确定,1. 为什么这不起作用,2. 如何修复它。
# allFileTypes is the list of all extensions in source_dir
# grabbed with function getFileExtList
allFileTypes = getFileExtList(source_dir)
# delete the blank file type
del allFileTypes[0]
# Open a window to choose the files to copy
copyList = eg.multchoicebox(msg='Select the file types to copy',
choices=(allFileTypes))
# List comprehension to make an ignore list for copytree
ignoreList = [x for x in allFileTypes if x not in copyList]
# Open a window to choose the destination directory
root_dir = eg.diropenbox(title='Choose Destination Directory')
# Take the basename of source_dir adding it to root_dir or os.mkdir will
# will break on the existing directory
dest_dir = os.path.join(root_dir, os.path.basename(source_dir))
# copytree everything from the source_dir to the dest_dir ignoring
# all files types not chosen from the list
copytree(source_dir, dest_dir, ignore=ignore_patterns(ignoreList))
最佳答案
copytree(source_dir, dest_dir, ignore=ignore_patterns(*ignoreList))
ignore_patterns
接收所有模式作为位置参数,而不是列表。
关于python - 将模式列表发送到 copytree 的ignore_patterns 会出现 TypeError : unhashable type: 'list' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18304881/
我正在尝试使用 python 复制文件/目录树。 是否可以使用 copytree 来复制所有以 foo 结尾的内容? 有一个 ignore_patterns 模式函数,我可以给它一个取反的正则表达式吗
我正在尝试在我的 python 程序中使用 shutil.copytree(libEntity,newDir) 并且出现以下错误: FileExistsError: [WinError 183] 当该
我正在尝试创建一个函数来复制所有目录和文件并将它们放入一个文件夹中。这个目录没有备份文件夹,所以我第一次使用复制树创建一个,每次重新运行这个程序时,它应该再次备份(包括以前的备份)。我遇到了 copy
整个晚上都在为此奋斗。三天前还可以工作,现在我再也无法让它工作了。 当我尝试使用这个时 def unzip_file(archiveFile, finalFolder, archiveFolder)
我想使用函数 shutil.copytree 从我的计算机上的本地服务器复制文件夹,我使用的是 macOS,但今天我遇到了问题,python 总是向我显示相同的消息,“[错误 1] 操作不允许”,但是
这是我正在编写的程序的一部分。目标是提取所有 GPX 文件,例如 G:\(在命令行中用 -e G:\指定)。它将创建一个“Exports”文件夹并在那里递归地转储所有具有匹配扩展名的文件。很好用, f
我有一些目录需要更新我正在使用以下代码 for newdir in newdirs: olddir = newdir.replace('h:\\','G:\\').replace('_acad
我的目录中有很多光栅文件 (600+),我需要将它们复制到新位置(包括它们的目录结构)。有没有办法使用 shutil.copytree() 跟踪复制状态?通常对于文件,我会使用下面的代码,但不确定如何
Python 的shutil.copytree 不是很灵活;在 copytree 中复制时添加对忽略权限的支持的最简单方法是什么(无需重写其实现)? 否则,copytree 会像这样失败: (…)”[
我正在尝试使用 shutil.copytree: shutil.copytree(SOURCE_DIR, TARGET_DIR, ignore=None) 此副本也包含在文件夹中。我只需要复制没有任何
考虑以下目录树 Work--->subdir1--->File1 | | | ---->File2 | -->subdir2--->Fi
我有一个函数: def path_clone( source_dir_prompt, destination_dir_prompt) : try: shutil.copytre
在 Python 脚本中,我复制了一个目录树,并想打印一些这样的文本... print("Copying... ", end="") shutil.copytree(src, dest) print(
documentation for the copytree function在 Python 2 版本的 shutil 中说, The source code for this should be
我想在调用 shutil.copytree() 时指定可忽略文件和目录的完整路径。有点像 def my_ignore(dir, files): # return ["exclude.file"
我正在尝试将目录复制到新位置。当它到达新位置时,我希望新目录的最后修改日期是它被复制到新位置的时间。 查看文档(https://docs.python.org/3/library/shutil.htm
我对 python 比较陌生。我正在尝试将一个目录复制到另一个保持结构的目录。 我正在使用 shutil.copytree(src, dst, symlinks=False, ignore=N
有没有一种方法可以使用绝对路径来过滤目录? shutil.copytree(directory, target_dir, ignore
我对 Python 还很陌生,所以请耐心等待。我想写一些东西来将文件从一个目录复制到另一个目录。我发现以下问题和解答:Here 在那里,我找到了这个答案: def copytree(src, dst,
我正在尝试编写一个 python 脚本来备份一个文件夹,并将其保留 x 天。 我用 shutil.copytree(source, finaldest) 我的问题是,原始文件的时间戳仍然存在,这意味着
我是一名优秀的程序员,十分优秀!