Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / How to use FileTimeToSystemTime()

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. How to use FileTimeToSystemTime()
#5791
Posted by: 2005-02-03 13:20:25
In the WinINet\ftp.htm, it references using the FileTimeToSystemTime() function to convert the Info.2/Info.3 time values to Rexx stem var.

I have the funcdef from the example,
  SystemTime = "16u,16u,16u,16u,16u,16u,16u,16u"
  FileTime   = "32u,32u"
  FUNCDEF("FileTimeToSystemTime", "32u, struct FileTime, struct SystemTime stor", "kernel32")

but not how to use the function.

Would someone post an example to get me started ?
Data is in stem Info, from FtpFindFirstFile(hConnect, , Info)

Thanks
Doug
Message2. Re: How to use FileTimeToSystemTime()
#5796
Posted by: Jeff Glatt 2005-02-03 16:58:53
Oh, I guess I must not have finished that example.

systemtime.1 = info.2
systemtime.2 = info.3
CALL filetimetosystemtime(systemtime, filetime)
SAY "Year =" filetime.1
SAY "Month =" filetime.2
SAY "Day =" filetime.4 '(' || convertday(filetime.3) || ')'
SAY "Hour =" filetime.5
SAY "Minute =" filetime.6
SAY "Second =" filetime.7
SAY "Milliseconds =" filetime.8

RETURN

convertday:
   SELECT ARG(1)
      WHEN 0 THEN RETURN "Sunday"
      WHEN 1 THEN RETURN "Monday"
      WHEN 2 THEN RETURN "Tuesday"
      WHEN 3 THEN RETURN "Wednesday"
      WHEN 4 THEN RETURN "Thursday"
      WHEN 5 THEN RETURN "Friday"
      OTHERWISE RETURN "Saturday"
   END

Message3. Re: How to use FileTimeToSystemTime()
#5820
Posted by: 2005-02-04 09:52:24
Great, that code works.

Now, a new wrinkle.
I'm getting the file name and size values back, but the date field (info.2/info.3) returned is zero.  I've tried this on 2 different ftp servers with the same result.  Am I missing something here ?
Sample result of date (as i formatted it) 010101-000000

...

  hFind = FtpFindFirstFile(hConnect, , Info) 
  Do forever
    DirSub = DirListFn.0 + 1
    DirListFn.0 = DirSub
    DirListFn.DirSub = Info.12
    DirListDate.DirSub = Ftp_ConvertDate(Info.2, Info.3)
    DirListSize.DirSub = Info.9
    If Bit(Info.1,4) then DirListType.DirSub = "D"
                     else DirListType.DirSub = "F"
    InternetFindNextFile(hFind, Info)
  end

....

Ftp_ConvertDate:
   systemtime.1 = arg(1)
   systemtime.2 = arg(2)
   CALL FileTimeToSystemTime(systemtime, filetime)
   FileDate = right(filetime.1,2,0) || right(filetime.2,2,0),
           || right(filetime.3,2,0)'-'right(filetime.5,2,0),
           || right(filetime.6,2,0) || right(filetime.7,2,0)

Return FileDate
Message4. Re: How to use FileTimeToSystemTime()
#5821
Posted by: 2005-02-04 12:34:56
Further experimenting shows the date is found in Info.6 and Info.7 instead of .2, .3
However, the date returned from one site was one day off, and from another site, 3 days off.
Sounds like a flaw in the windows routine.
I should have known, mixing unix with windows was asking for trouble :-)  Whoops, there goes my mainframe bias.
Message5. Re: How to use FileTimeToSystemTime()
#5822
Posted by: Jeff Glatt 2005-02-04 15:30:47
Info.2 and Info.3 are the "creation" date. Info.4 and Info.5 are the "last accessed" date. Info.6 and Info.7 are the "last modified" date.

As I recall, Unix file systems do not store a creation date (which frankly, I think is a real oversight), nor a "last accessed" date. In such a case, the creation date and last accessed dates are set to 0 (to indicate that this information isn't valid). Unix stores only a "last modified" date, so that's why you're getting only that field filled in. (If you were communicating with a file on a Windows server, you'd get all three times).

Now, there is another consideration. Apparently, Unix times are referenced from GMT. Windows file times are always in local time. So, you may need to convert the Unix time from GMT to your local time. That may account for why you're getting wrong times. I don't know because I've never experimented with that. (But who knows, it could be some server strangeness).

I once wrote a routine in C that converted a time from GMT to local time. If you need it, I can either translate it to REXX, or whip up a DLL add-on function you can call to do it.
Message6. Re: How to use FileTimeToSystemTime()
#5825
Posted by: Jeff Glatt 2005-02-04 16:07:41
Oh there it is. The Windows operating system already has a function to adjust UTC to local time. Try this:
systemtime = "16u,16u,16u,16u,16u,16u,16u,16u"
filetime = "32u,32u"
FUNCDEF("FileTimeToSystemTime", "32u, struct FILETIME, struct SYSTEMTIME stor", "kernel32")
FUNCDEF("FileTimeToLocalFileTime", "32u, struct FILETIME, struct FILETIME stor", "kernel32")

filetime.1 = info.2
filetime.2 = info.3
/* Do the following line only if the file was sent from a UNIX system */
CALL filetimetolocalfiletime(filetime, filetime)
CALL filetimetosystemtime(filetime, time)
SAY "Year =" time.1
SAY "Month =" time.2
SAY "Day =" time.4 '(' || convertday(time.3) || ')'
SAY "Hour =" time.5
SAY "Minute =" time.6
SAY "Second =" time.7
SAY "Milliseconds =" time.8

RETURN

convertday:
   SELECT ARG(1)
      WHEN 0 THEN RETURN "Sunday"
      WHEN 1 THEN RETURN "Monday"
      WHEN 2 THEN RETURN "Tuesday"
      WHEN 3 THEN RETURN "Wednesday"
      WHEN 4 THEN RETURN "Thursday"
      WHEN 5 THEN RETURN "Friday"
      OTHERWISE RETURN "Saturday"
   END
Message7. Re: How to use FileTimeToSystemTime()
#5834
Posted by: 2005-02-05 07:44:14
This was interesting, however, it only seems to have moved the time back by 6 hrs.  The time (when available) were spot on, only the day was +1  (or +24 hrs)

On a true unix host, a file created on 02/04/2005 at 16:27, is being reported by the program as 02/05/2005 at 16:27 (or with the new mod, 10:27).

On a sort of unix host (VMS V7.3-1 Alpha Server) i get the same thing for a newly created file (+1 day), however, a file created in 2004 is reported as -3 days off (is 10/6/2004, reports as 10/3/2004) however, the time is also reporting to be zero (and a dir command doesn't show a time either for prior years).

I suppose I could just back off a day, but this is strange. Makes one wonder if there is a leap year flaw in the routine.

I don't suppose, using WinINet, one could just get the standard line returned from a "dir" and then parse it ?
Message8. Re: How to use FileTimeToSystemTime()
#5835
Posted by: 2005-02-05 08:03:20
Update to prior post.

I expanded my testing to a directory with more files in it.  On the "true unix" host.

It seems the problem is worse than I reported, examples:

unix- May 19 2004 (no time)   reports as 05/03/04 00:00
unix- May 21 2004 (no time)   reports as 05/05/04 00:00
unix- Jan 23 2005 18:39       reports as 01/00/05 18:39
                              note the 00 day
unix- Feb 1  2005 22:13       reports as 02/02/05 22:13
unix- Jan 21 2005 05:16       reports as 01/05/05 05:16

so much for the adjust by one day indea

guess i'm open for another way to do ftp, where i can get a valid dir listing.
My goal here was to create a sync program between a pc directory and it's counterpart at a web host.
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2024-10-5  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0