geekcomputers / geekcomputers/Python

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

Đang mở
#294 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Python
Star
35.4k
Fork
12.9k
Merge trung bình
2 giờ 37 phút
Pull request đã merge (30 ngày)
1

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện hành vi với script được cung cấp, A.jar và copy.txt, sau đó kiểm tra lệnh gọi zipfile.ZipFile và tên entry của zf.write. Xác nhận xem archive có chứa file entry dự kiến dưới org hay không và liệu một entry hiện có có bị thay thế hay không; issue được hoàn tất khi hành vi này được chứng minh một cách đáng tin cậy.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
tooling
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.