geekcomputers / geekcomputers/Python
Python-Copying a file into a folder present in a A.jar file without extracting
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 35.4k
- Forks
- 12.9k
- Merge moyen
- 2 h 37 min
- PR mergées (30 j)
- 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)
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par reproduire le comportement avec le script fourni, A.jar et copy.txt, puis examinez l’appel à zipfile.ZipFile et le nom d’entrée de zf.write. Vérifiez si l’archive contient l’entrée de fichier prévue sous org et si une entrée existante est remplacée ; l’issue est terminée lorsque ce comportement a été démontré de manière fiable.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- tooling
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100