مشكلة في كود البايثون! من فضلك انا بحاجة الى مساعدة

‘zip’ is not recognized as an internal or external command,

operable program or batch file.

backup failed

n.py:

`import os

import time

source=[r’C:\Users\AiMeN\Desktop\a’]

where=’/This PC/Documents’

ntarget=where + time.strftime(’%Y%m%d%H%M%S’) + ‘.zip’

zip_command=“zip -qr’%s’%s”%(ntarget,’’.join(source))

if os.system(zip_command) == 0:

print(“success backupto”,ntarget)

else :

print(“backup failed”)

`

يرجى الدخول لحسابك أو تسجيل حساب لتستطيع إضافة تعليق
حساب جديد دخول

التعليقات

أنت تحاول تنفيذ أمر zip عبر command line

هذا الأمر غير موجود في ويندوز (إفتح cmd وجرب الأوامر قبل وضعها في البرنامج)

هذا الأمر موجود في لينكس

إستخدم مكتبة zip في python

بدلا من التعامل مع cmd

انا اتعلم البايثون و احاول كتابة برنامج يقوم بعمل نسخة احتياطية من جميع الملفات المهمة لدي ووضعها في ملف مضغوط .فما الحل

جرب هذا

import os
import zipfile
import time
def zipdir(path, output):
    ziph = zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED)
    for root, dirs, files in os.walk(path):
        for file in files:
            ziph.write(os.path.join(root, file))
    ziph.close()
inputDir = r'C:\myFolder'
outputZip = 'backup-myFolder-' + time.strftime('%Y%m%d%H%M%S') + '.zip'
zipdir(inputDir, outputZip)

المصدر :