geekcomputers / geekcomputers/Python
Python-Copying a file into a folder present in a A.jar file without extracting
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 35.4k
- Forks
- 12.9k
- Avg merge
- 2h 37m
- Merged PRs (30d)
- 1
Description
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the behavior with the provided script, A.jar, and copy.txt, then inspect the zipfile.ZipFile call and the zf.write entry name. Confirm whether the archive contains the intended file entry under org and whether an existing entry is replaced; the issue is complete when this behavior is demonstrated reliably.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100