I am trying to change the last modified time of all the files and folders present in a zip file. If I try the script line-by-line in interpreter, the last-modified time seems to have been changed. But the same is not reflected in the zip file.
I am using the zipfile module in python.
Below is my source code.
import zipfile as zp
import datetime
import datetime
def main():
zipfile = raw_input("enter the path for your zipfile :")
if os.path.exists(zipfile) and zp.is_zipfile(zipfile):
time = raw_input("enter the time for which your files and folders in zip file want to be changed. format: dd-mm-yyyy HH:MM:SS -")
if time is not None :
time = datetime.datetime.strptime(time, "%d-%m-%Y %H:%M:%S")
newtime = time
time = (time.year, time.month, time.day, time.hour, time.minute, time.second)
print "time =", time
z = zp.ZipFile(zipfile, "a", zp.ZIP_DEFLATED)
z.printdir()
try :
for i in range(len(z.filelist)):
z.infolist()[i].date_time = time
z.printdir()
finally :
z.close()
else :
print "you have not entered a valid time!"
else :
print " you have not entered a valid zipfile name. "
if __name__ == "__main__":
main()