mio programma senza intoppi, ma voglio che i miei file da FTP per essere zip nel mio disco localefile Zipping in pitone
mio problema: solo 1 file sia compresso dopo aver chiamato la mia funzione main()
Ecco il mio codice:
principale
import os
import upload
import download
import zipfile
import ConfigParser
import ftputil
def main():
#create a folder Temp on d drive for later use
path = r'D:\Temp'
os.mkdir(path)
#parse all the values at config.ini file
config = ConfigParser.ConfigParser()
config.readfp(open('config.ini'))
server = config.get('main', 'Server')
username = config.get('main', 'Username')
password = config.get('main', 'Password')
uploads = config.get('main', 'Upload folder')
downloads = config.get('main', 'Download folder')
#connect to ftp
ftp = ftputil.FTPHost(server, username, password)
dirlist = ftp.listdir(downloads)
for list in dirlist:
ftp.chdir(downloads)
target = os.path.join(path, list)
ftp.download(list, target)
#########################################################
# THis section is where algo fails but the program run#
########################################################
#zipping files
absolute_path = r'D:\Temp'
dirlist = os.listdir(absolute_path)
filepath = r'D:\Temp\project2.zip'
for list in dirlist:
get_file = os.path.join(absolute_path, list)
zip_name = zipfile.ZipFile(filepath, 'w')
zip_name.write(get_file, 'Project2b\\' + list)
if __name__ == '__main__':
print "cannot be"
Ti archivia costituito da ultimo file 'target'? –
Manca il metodo di compressione, zipfile.ZIP_DEFLATED se non viene fornito, i file non verranno compressi. Dovrebbe essere zipfile.ZipFile (filepath, 'w', zipfile.ZIP_DEFLATED) per includere la compressione –