geekcomputers / geekcomputers/Python

Python-Copying a file into a folder present in a A.jar file without extracting

Aperta
#294 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
35.4k
Fork
12.9k
Merge medio
2h 37m
PR unite (30g)
1

Descrizione

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)

Extract to get A.jar.zip

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo il comportamento con lo script fornito, A.jar e copy.txt, quindi esamina la chiamata a zipfile.ZipFile e il nome della voce di zf.write. Verifica se l’archivio contiene la voce di file prevista sotto org e se una voce esistente viene sostituita; l’issue è completa quando questo comportamento è stato dimostrato in modo affidabile.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
tooling
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.