geekcomputers / geekcomputers/Python
Python-Copying a file into a folder present in a A.jar file without extracting
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 35.4k
- 派生
- 12.9k
- 平均合并
- 2 小时 37 分钟
- 30 天内合并 PR
- 1
描述
Hi ,
I was trying to copy a file into a A.jar (without extracting it) but it didn't work.
Suppose i have file copy.txt in D:\python\copy.txt and i want this file to be copied into my A.jar/org/here
for this I have written a code in python but what it is doing is , It is taking the contents of copy.txt and pasting the content to target dir-> A.jar/org/. It is not pasting the file instead it is pasting the content. I want the file to be copied with the content and if the file is already exist it will replace it in the target dir.
Please see my below code and suggest .
import zipfile, os
def show_jar_classes(jar_file):
zf = zipfile.ZipFile(jar_file, 'a')
try:
#Code to write inside org folder in inside z.jar
dir=input("please give the source file dir along with the file")# taking complete path frm user
m='/'
dir= dir.replace('\\',m) #formating the path by replacing '\' with '/'
clas=os.path.basename(dir) #extracting the file name from the given path
zf.write(dir, "org\\"+clas) #writing into A.jar/org/
finally:
zf.close()
jar_file = 'D:/python/A.jar'
show_jar_classes(jar_file)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先使用提供的脚本、A.jar 和 copy.txt 重现该行为,然后检查 zipfile.ZipFile 调用和 zf.write 的条目名称。确认归档是否包含 org 下预期的文件条目,以及现有条目是否会被替换;当这一行为得到可靠演示时,该 issue 即可完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100