简体   繁体   English

python TarFile.extractall 命令删除目标目录下的文件

[英]python TarFile.extractall command deletes the files in the target directory

this is a simple piece of code in our production env.这是我们生产环境中的一段简单代码。 Python version 2.7 Python 2.7版

tar = tarfile.open(fileobj=pipe, mode='r|gz')
tar.extractall(d)

The finally blocks closes the tar file also. finally 块也会关闭 tar 文件。

   finally:
        if tar:
            tar.close()

However, on windows it is observed that some files in the target directory are deleted after the extractall().但是,在 windows 上,观察到目标目录中的一些文件在 extractall() 之后被删除。 Is this possible?这可能吗? has anyone seen such issue before?有没有人见过这样的问题?

Windows is windows 2016 Windows 是 windows 2016

In my experience tarfile.extractall() overwrites files and directories.以我的经验 tarfile.extractall() 会覆盖文件和目录。 If you edit some extracted files and than run again extractall(), you will obtain the "original" files.如果您编辑一些提取的文件,然后再次运行 extractall(),您将获得“原始”文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 python 解压文件并使用 tarfile.extractall() python 提取某些文件 - Untar files with python and extract certain files with tarfile.extractall() python tarfile.extractall()的Unicode问题(Python 2.7) - Unicode issues with tarfile.extractall() (Python 2.7) TarFile.extractall() 处理正常,但不创建任何新文件或目录 - TarFile.extractall() processes fine but doesn't create any new files or directories 为什么tarfile.extractall默认忽略错误? - Why does tarfile.extractall ignore errors by default? tarfile.extractall()引发IsADirectoryError,因为存在提取路径 - tarfile.extractall() raises IsADirectoryError because extraction path exists 使用tarfile.extractall()解压缩的tar.gz文件夹的其他名称 - Different name of unpacked tar.gz folder using tarfile.extractall() Tarfile/Zipfile extractall() 更改某些文件的文件名 - Tarfile/Zipfile extractall() changing filename of some files python版本2.4中tarfile模块的“extractall()”的替代方案 - Alternative of “extractall()” of tarfile module in python version 2.4 使用 tarfile (Python) 仅压缩给定目录中的文件 - Compressing only the files inside a given directory using tarfile (Python) 如何在不添加目录层次结构的情况下使用 Python 将文件添加到 tarfile? - How can files be added to a tarfile with Python, without adding the directory hierarchy?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM