1

I am quire sure, this is something very common. I want to download files from a https-server and want to keep the original (changed) date. So it should not show me the date the one which is after downloaded. Here I am using this way.

        filename = file.text
            file = session.get(url, verify=False) 
            if file.endswith('arg'):
                    file = open('C:/RD/M/' + filename, 'wb+')
                    file.write(file.content)
                    file.close()
            else:
            'do something'

Is there any way to add something after file.write(file.content)?

Thanks for info in advance

  • possible duplicate of [how can I set the last modified time of a file from python?](http://stackoverflow.com/questions/11348953/how-can-i-set-the-last-modified-time-of-a-file-from-python) – Peter Wood Dec 17 '14 at 13:32
  • Thanks Peter, but this is not quite easy to implement in my file.write mechanism. – michaelsteven Dec 17 '14 at 14:00
  • After closing the file, use [os.utime](https://docs.python.org/2/library/os.html#os.utime) to set the date. – Peter Wood Dec 17 '14 at 15:01
  • @PeterWood thanks again. If I put this like that, I get an error unfortunately. `atime = os.path.getatime(file)` `mtime = os.path.getatime(file)` `file.close()` `os.utime(file, (atime, mtime))` – michaelsteven Dec 18 '14 at 12:56
  • You have `getatime` twice, and you are setting file to have the same `atime` and `mtime` as before. Also `file` isn't a good name for a variable as it is a [builtin function](https://docs.python.org/2/library/functions.html#file). You need to get the time from the server, which I would need to search to find out. Sounds like you have a few new problems to work on before asking another question. – Peter Wood Dec 18 '14 at 13:12

0 Answers0