0

need to download a zip from website as save it as it is without altering or making any changes to timestamps

def getfile("Download URL"):
    r = s.get("Download URL")  
    z = zipfile.ZipFile(io.BytesIO(r.content)) 
    z.extractall("C:\folder") # need to save file as it is instead of extract
    print(" Done" )

In above code I want to use the file as it is instead of extracting using z.extractall

extractall changes file create dates which i do not want I want to save zip as received from download link

Download URL can not have a zip file name as it is dynamic link

Yeloblu
  • 1
  • 3
  • 1
    Does this answer your question? [Unzipping directory structure with python](https://stackoverflow.com/questions/639962/unzipping-directory-structure-with-python) – Grant Williams Jan 21 '20 at 22:45
  • You want to keep it as a zip file instead of extracting the files? Just write `r.content` to a file. – Barmar Jan 21 '20 at 22:45
  • this will create a new zip file with contents , with fresh time stamps – Yeloblu Jan 21 '20 at 23:06
  • Have you tested what @Barmar suggested? I thought surely that would work... What timestamps are you talking about, anyway? – AMC Jan 21 '20 at 23:38
  • yes , It creates a new file because you are performing a 'write' operation, this will change the file created/modified time stamp from original to current. There are options to save old time stamps and create file with custom time stamp , but I feel that is incorrect. `with open(r'test.zip', 'wb') as f:` `f.write (r.content)` – Yeloblu Jan 22 '20 at 13:05

0 Answers0