geekcomputers / geekcomputers/Python

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

Abierto
#294 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
35.4k
Forks
12.9k
Merge medio
2 h 37 min
PR fusionados (30 d)
1

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza reproduciendo el comportamiento con el script proporcionado, A.jar y copy.txt; después, inspecciona la llamada a zipfile.ZipFile y el nombre de entrada de zf.write. Confirma si el archivo contiene la entrada de archivo prevista bajo org y si se reemplaza una entrada existente; la issue estará completa cuando este comportamiento se haya demostrado de forma fiable.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
tooling
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.