FoxPro Programming
Preserve Datemodified
Gravatar is a globally recognized avatar based on your email address. Preserve Datemodified
  Toni Köhler
  All
  Oct 28, 2024 @ 02:24pm

Hi Rick,

I would like to download files from the web and preserve the datemodified from webserver. Do you have a solution for me?

loHttp	  = CREATEOBJECT("wwHttp")
loHttp.HttpGet(tcRemotePath, , , tcLocalPath)

Regards Toni

Gravatar is a globally recognized avatar based on your email address. re: Preserve Datemodified
  Rick Strahl
  Toni Köhler
  Oct 29, 2024 @ 09:24am

You can't directly do that because you're not dealing with a file system - you're retrieving a binary stream and writing it out to disk.

What you can do however is capture the Last-modified response header and then 'touch' the file and change the file date after you save it.

Something like this:

DO wwdotnetbridge
DO wwhttp 
LOCAL loHttp as wwHttp, loBridge as wwDotNetBridge
LOCAL lcFile, lcDate

lcFile = "c:\temp\wwipstuff.zip"

*** Download file
loHttp = CREATEOBJECT("wwHttp")
loHttp.Get("https://west-wind.com/files/wwipstuff.zip","c:\temp\wwipstuff.zip")
IF(loHttp.nError != 0)
   ? loHttp.cErrorMsg
   ReTURN
ENDIF

*** Get the Modified date
lcDate = loHttp.Gethttpheader("Last-modified")
? lcDate  && GMT Date

loBridge = GetwwDotnetBridge()

*** Convert GMT Date to DateTime
ldDate = loBridge.InvokeStaticMethod("System.DateTime","Parse", lcDate)
? ldDate  && Real date

*** Set the file Date
loFile = loBridge.CreateInstance("System.IO.FileInfo", lcFile)
loFile.LastWriteTime = ldDate

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Preserve Datemodified
  Toni Köhler
  Rick Strahl
  Oct 29, 2024 @ 07:12pm

Hi Rick,

wow, that's realy cool. The wwDotNetBridge is realy powerfull.

Thanks for you sample.

Regards Toni

Gravatar is a globally recognized avatar based on your email address. re: Preserve Datemodified
  Rick Strahl
  Toni Köhler
  Oct 29, 2024 @ 08:15pm

Not so much wwDotnetBridge but .NET... so much useful functionality that would be painful to do with Fox or DECLARE code.

+++ Rick ---

© 1996-2025