geekcomputers / geekcomputers/Python

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

Offen
#294 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
35.4k
Forks
12.9k
Ø Merge
2 Std. 37 Min.
Gemergte PRs (30 T.)
1

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, das Verhalten mit dem bereitgestellten Skript, A.jar und copy.txt zu reproduzieren, und untersuche dann den Aufruf von zipfile.ZipFile und den Eintragsnamen von zf.write. Bestätige, ob das Archiv den vorgesehenen Dateieintrag unter org enthält und ob ein vorhandener Eintrag ersetzt wird; das Issue ist abgeschlossen, wenn dieses Verhalten zuverlässig demonstriert wurde.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.