FileDateTime() for Unicode

New to FreeBASIC? Post your questions here.
Post Reply
newbieforever
Posts: 117
Joined: Jun 21, 2018 11:14

FileDateTime() for Unicode

Post by newbieforever »

Hi! A new newbie question:

There is a FileDateTime() function in file.bi and vbcompat.bi.

Is there an equivalent function supporting file names containing Unicode characters (Windows)?

(I suppose it's pointless to ask if there is a function to set the file modification date...) EDITED: In the course of discussion I extended my request to both GetFileTime and SetFileTime.
Last edited by newbieforever on Feb 15, 2019 12:56, edited 1 time in total.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: FileDateTime() for Unicode

Post by Josep Roca »

No, but it is not difficult to write a replacement:

Code: Select all

' ========================================================================================
' * Unicode replacement for Free Basic's FileDateTime.
' Returns the file's last modified date and time as Date Serial.
' wszFileName : Filename to retrieve date and time for.
' Return Value : Returns a Date Serial.
' ========================================================================================
PRIVATE FUNCTION AfxFileDateTime (BYREF wszFileName AS WSTRING) AS DOUBLE
   DIM fd AS WIN32_FIND_DATAW
   DIM hFind AS HANDLE = FindFirstFileW(wszFileName, @fd)
   IF hFind = INVALID_HANDLE_VALUE THEN RETURN 0
   FindClose hFind
   DIM ft AS FILETIME
   FileTimeToLocalFileTime(@fd.ftLastWriteTime, @ft)
   DIM st AS SYSTEMTIME
   FileTimeToSystemTime(@ft, @st)
   DIM dt AS DOUBLE
   SystemTimeToVariantTime @st, @dt
   RETURN dt
END FUNCTION
' ========================================================================================
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: FileDateTime() for Unicode

Post by Josep Roca »

> (I suppose it's pointless to ask if there is a function to set the file modification date...)

There is a Windows function called SetFileTime:
https://docs.microsoft.com/en-us/window ... etfiletime
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FileDateTime() for Unicode

Post by dodicat »

You could try the crt functions (they usually have wide string options)

Code: Select all


#include "crt.bi"



dim as _stat filestat

dim as wstring* 50 ws= wstr("datetest.txt") 'need your filename

var v=_wstat(@ws,@filestat)
if v=0 then
print, ws;" info"
print " File access time     ";*ctime(@filestat.st_atime)
print " File modify time     ";*ctime(@filestat.st_mtime)
print " File changed time    ";*ctime(@filestat.st_ctime)
else
    print "unable to read ";ws
    end if
sleep
            
           
  
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FileDateTime() for Unicode

Post by dodicat »

directory( perhaps containing unicode filenames ) experiment.

Code: Select all


#include "crt.bi"

const size=10000

declare function wsystem_ cdecl alias "_wsystem" (byval as wstring ptr) as long

sub save(filename as wstring,content as wstring) 'not used here
    dim as wstring * 20 w="wt+,ccs=utf-8"
   var fp = _wfopen(@filename,@w) 
   if fp then fputws(@content,fp) else print "could not save "+filename
   fclose(fp)
end sub


sub load(filename as wstring,content as wstring)
     dim as wstring * 20 r="rt+,ccs=utf-8"
     dim as wstring * size t
   dim as file ptr fp = _wfopen(@filename,@r)
   if fp=0 then print "Unable to load ";filename:sleep:exit sub
   while 1
    if (fgetws (@t,size,fp)= 0)then exit while
    content+=t
wend
fclose(fp)
end sub

Sub wstring_split( s_in As wString ptr,chars As String,result() As wString ptr)
    redim result(0)
    dim as wstring ptr s=s_in
    Dim As wString * 5000 var1,var2
Dim As long pst,LC=len(chars)
      #macro split(stri)
    pst=Instr(stri,chars)
    var1="":var2=""
    If pst<>0 Then
    var1=wstr(Mid(stri,1,pst-1))
    var2=wstr(Mid(stri,pst+LC))
    Else
    var1=stri
End if
    if len(var1) then 
    redim preserve result(1 to ubound(result)+1)
    result(ubound(result))=allocate(5000)
    *result(ubound(result))=(var1)
    end if
    #endmacro
   Do
   split(*s):*s=var2
Loop Until var2=""
End Sub

wsystem_ ("chcp 65001") 'change codepage (for session)
wsystem_("dir /b >dir.dat")' list the files into dir.dat
dim as wstring * 10000 content
load("dir.dat",content)  'load the file

redim as wstring ptr w()

wstring_split(@content,wchr(10),w())'split the file into individual names


 
dim as _stat filestat

for n as long=lbound(w) to ubound(w)

dim as wstring* 500 ws= *w(n)''get each filename


var v=_wstat(@ws,@filestat)
if v=0 then
print, ws;" info (file";n;")"
print " File access time     ";*ctime(@filestat.st_atime)
print " File modify time     ";*ctime(@filestat.st_mtime)
print " File changed time    ";*ctime(@filestat.st_ctime)
else
    print "unable to read ";ws
end if
print "-------------------------------"
next n
print "done, number of file processed  ";ubound(w) 
sleep
for n as long=lbound(w) to ubound(w)
    deallocate w(n)
next

            
           
 
newbieforever
Posts: 117
Joined: Jun 21, 2018 11:14

Re: FileDateTime() for Unicode

Post by newbieforever »

Thank you, dodicat. I see now that there would be a way to get the file's timestamp, but to implement a solution to set e.g. the last modification time would be beyond my possibilities...
PaulSquires
Posts: 1002
Joined: Jul 14, 2005 23:41

Re: FileDateTime() for Unicode

Post by PaulSquires »

Jose has answered your question.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FileDateTime() for Unicode

Post by dodicat »

I can run Josep Roca's code from within WinFBX-Master.
If I try another folder I get errors from other inc files
example error from cwindow.inc
File not found, "Afx/AfxCtl.inc" in '#include once "Afx/AfxCtl.inc"'
Anyway i got a runner from within WinFBX-Master, comparing the crt method.

Code: Select all

 Active code page: 65001
              .gitattributes info (file 1)
 File access time     Sat Mar 03 07:11:44 2018

 File modify time     Tue Mar 27 14:59:14 2018

 File changed time    Sat Mar 03 07:11:44 2018

------
josep roca
2018/03/27 14:59:14
--------------------------------
              .gitignore info (file 2)
 File access time     Sat Mar 03 07:11:44 2018

 File modify time     Tue Mar 27 14:59:14 2018

 File changed time    Sat Mar 03 07:11:44 2018

------
josep roca
2018/03/27 14:59:14
--------------------------------
              Afx info (file 3)
 File access time     Wed May 30 10:28:09 2018

 File modify time     Wed May 30 10:28:09 2018

 File changed time    Tue Mar 27 14:59:14 2018

------
josep roca
2018/05/30 10:28:09

--------------------------------
              Examples info (file 3)
 File access time     Tue Mar 27 14:59:25 2018

 File modify time     Tue Mar 27 14:59:25 2018

 File changed time    Tue Mar 27 14:59:15 2018

------
josep roca
2018/03/27 14:59:25
--------------------------------
              FBIDETEMP.bas info (file 4)
 File access time     Tue Feb 12 01:57:50 2019

 File modify time     Tue Feb 12 01:57:50 2019

 File changed time    Tue Feb 12 01:57:50 2019

------
josep roca
2019/02/12 01:57:50
--------------------------------
              FBIDETEMP.exe info (file 5)
 File access time     Tue Feb 12 01:57:53 2019

 File modify time     Tue Feb 12 01:57:53 2019

 File changed time    Tue Feb 12 01:57:53 2019

------
josep roca
2019/02/12 01:57:53
--------------------------------
              FBWinSpy info (file 6)
 File access time     Tue Mar 27 14:59:25 2018

 File modify time     Tue Mar 27 14:59:25 2018

 File changed time    Tue Mar 27 14:59:25 2018

------
josep roca
2018/03/27 14:59:25
--------------------------------
              New folder info (file 7)
 File access time     Tue Feb 12 01:57:19 2019

 File modify time     Tue Feb 12 01:57:19 2019

 File changed time    Tue Feb 12 01:33:40 2019

------
josep roca
2019/02/12 01:57:19
--------------------------------
              Position.dat info (file 8)
 File access time     Tue Mar 27 15:03:22 2018

 File modify time     Wed Mar 28 00:33:59 2018

 File changed time    Tue Mar 27 15:03:22 2018

------
josep roca
2018/03/28 00:33:59
--------------------------------
              README.md info (file 9)
 File access time     Sat Mar 03 07:11:44 2018

 File modify time     Tue Mar 27 14:59:14 2018

 File changed time    Sat Mar 03 07:11:44 2018

------
josep roca
2018/03/27 14:59:14
--------------------------------
              timestamp.bas info (file 10)
 File access time     Tue Feb 12 01:18:05 2019

 File modify time     Tue Feb 12 01:53:42 2019

 File changed time    Tue Feb 12 01:18:05 2019

------
josep roca
2019/02/12 01:53:42
--------------------------------
              TLB_100 info (file 11)
 File access time     Tue Mar 27 14:59:25 2018

 File modify time     Tue Mar 27 14:59:25 2018

 File changed time    Tue Mar 27 14:59:25 2018

------
josep roca
2018/03/27 14:59:25
--------------------------------
              СергeйСергeй.txt info (file 12)
 File access time     Tue Feb 12 01:28:31 2019

 File modify time     Mon Jan 28 18:14:48 2019

 File changed time    Tue Feb 12 01:28:31 2019

------
josep roca
2019/01/28 18:14:48
--------------------------------
done, number of file processed   12 
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FileDateTime() for Unicode

Post by dodicat »

Here is Josep Roca's function (getter) free from his afx library.
(open pipe doesn't get unicode , but I have used it for a running example)

Code: Select all

 

#Define UNICODE
#include "windows.bi"
#include "vbcompat.bi"
' ========================================================================================
' * Unicode replacement for Free Basic's FileDateTime.
' Returns the file's last modified date and time as Date Serial.
' wszFileName : Filename to retrieve date and time for.
' Return Value : Returns a Date Serial.
' ========================================================================================
#inclib "oleaut32"
extern "Windows"
declare function SystemTimeToVariantTime(byval lpSystemTime as LPSYSTEMTIME, byval pvtime as DOUBLE ptr) as INT_
end extern

 FUNCTION AfxFileDateTime (BYREF wszFileName AS WSTRING) AS DOUBLE
   DIM fd AS WIN32_FIND_DATAW
   DIM hFind AS HANDLE = FindFirstFileW(wszFileName, @fd)
   IF hFind = INVALID_HANDLE_VALUE THEN RETURN 0
   FindClose hFind
   DIM ft AS FILETIME
   FileTimeToLocalFileTime(@fd.ftLastWriteTime, @ft)
   DIM st AS SYSTEMTIME
   FileTimeToSystemTime(@ft, @st)
   DIM dt AS DOUBLE
   SystemTimeToVariantTime @st, @dt
   RETURN dt
END FUNCTION


' ========================================================================================
shell ("chcp 65001") 'change codepage (for session)
print
print "Folder content:"
print
shell "dir /b"
print
print "press a key to continue . . ."
sleep

print "==========================="

dim as integer f=freefile
Open Pipe "dir /b" For Input As #f

Dim As wString * 500 ln  'waste of time here, could be string instead

Do Until EOF(1)
    Input #f, ln  '' fails for unicode
    print "file   ";ln
    var a= AfxFileDateTime (ln)
    Print Format(a, "yyyy/mm/dd hh:mm:ss") 
    print "------------------------------"
    
Loop

Close #f
sleep


 
newbieforever
Posts: 117
Joined: Jun 21, 2018 11:14

Re: FileDateTime() for Unicode

Post by newbieforever »

Thanks to all!

This is another solution, a code adapted (by me) from a very old posting. It uses the Windows function GetFileTime().

Code: Select all

BOOL GetFileTime(
  HANDLE     hFile,
  LPFILETIME lpCreationTime,
  LPFILETIME lpLastAccessTime,
  LPFILETIME lpLastWriteTime
);
And it works perfectly.

Code: Select all

#Include once "windows.bi"
#Include once "vbcompat.bi"

Declare Function GetFileTimeW(file as Wstring, t As String = "w") As Double

Dim As Wstring * 500 file = "Notečšž.txt"
Dim As String        t    = "w"                         ' 'c' – create, 'a' – access, 'w' – write
Dim As Double        tst  = GetFileTimeW(file, t)       ' 't' is optional

Print FORMAT(tst, "dd.mm.yyyy hh:mm:ss")

Function GetFileTimeW(file as Wstring, t As String) As Double
  Dim As FILETIME   ftCr, ftAc, ftWr
  Dim As SYSTEMTIME stUTC, stLo
  Dim As HANDLE     fh
  Dim As Integer    res
  Dim As Double     tst
  fh  = CreateFileW(file, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0)
  res = GetFileTime(fh, @ftCr, @ftAc, @ftWr)
  If t = "c" Then FileTimeToSystemTime(@ftCr, @stUTC)
  If t = "a" Then FileTimeToSystemTime(@ftAc, @stUTC)
  If t = "w" Then FileTimeToSystemTime(@ftWr, @stUTC)
  SystemTimeToTzSpecificLocalTime(0, @stUTC, @stLo)
  tst = DATESERIAL(stLo.wYear, stLo.wMonth, stLo.wDay) + TIMESERIAL(stLo.wHour, stLo.wMinute, stLo.wSecond) 
  If stLo.wYear = 1601 Then tst = DATESERIAL(0, 1, 1)
  close fh
  Return tst
End Function

' https://www.freebasic.net/forum/viewtopic.php?p=32365#p32365
(Could the c/a/w differentiation be written more elegant? How to remove the warning from 'close fh'?)

My next desire would of course be a code in which the Windows function FileSetTime() is used (hint by Josep, above)...

Code: Select all

BOOL SetFileTime(
  HANDLE         hFile,
  const FILETIME *lpCreationTime,
  const FILETIME *lpLastAccessTime,
  const FILETIME *lpLastWriteTime
);
Last edited by newbieforever on Feb 14, 2019 21:15, edited 1 time in total.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: FileDateTime() for Unicode

Post by Josep Roca »

> How to remove the warning from 'close fh'?

Using the correct API function (CloseHandle) instead of Close.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FileDateTime() for Unicode

Post by dodicat »

There are plenty of examples if you google for C examples.
Here is a quickie for a straight file, I'll mess around later for a unicode method.

Code: Select all

 
 

#include "windows.bi"

#include "crt.bi"

function setfiletocurrent(file as wstring) as boolean  'pulled from google
   ' Create a systemtime struct
   dim as SYSTEMTIME thesystemtime
   ' Get current system time and then change the day to the 3rd
   ' You can also change year, month, day of week etc
   GetSystemTime(@thesystemtime)
   thesystemtime.wDay = 3
   ' Create a FILETIME struct and convert our new SYSTEMTIME
   ' over to the FILETIME struct for use in SetFileTime below
   dim as FILETIME thefiletime
   SystemTimeToFileTime(@thesystemtime,@thefiletime)
   ' Get a handle to our file and with file_write_attributes access
   dim as HANDLE filename = CreateFile(file, FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ or FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)
    'Set the file time on the file
   function=SetFileTime(filename, NULL, NULL,@thefiletime)
   ' Close our handle.
   CloseHandle(filename)
end function

function datestamp(filename as wstring ptr) as wstring ptr
dim as wstring* 500 ws= *filename
dim as _stat filestat
var v=_wstat(@ws,@filestat)
static as wstring * 1000 s :s="   "
if v=0 then
    s+=ws+chr(10)
    s+=" The most recent time that: " +chr(13,10)
    s+=" The item was accessed.                  " + *ctime(@filestat.st_atime)
    s+=" The item's contents were modified.      " + *ctime(@filestat.st_mtime)
    s+=" The item's permissions were changed.    " + *ctime(@filestat.st_ctime)
    s+=" The file size is                        "+ str(filestat.st_size)
else
    s= "unable to read "+ws
end if
return @s
end function

shell "echo HELLO THERE > brand_new.txt"

print *datestamp("brand_new.txt")
print "please wait five seconds . . ."
sleep 5000

dim as wstring * 20 w="brand_new.txt"
 print setfiletocurrent(w)

print *datestamp("brand_new.txt")
print "press a key to end . . ."
sleep

kill "brand_new.txt"
 
newbieforever
Posts: 117
Joined: Jun 21, 2018 11:14

Re: FileDateTime() for Unicode

Post by newbieforever »

Hi!

This is "nearly perfect": Both GetFileTimeW() and SetFileTimeW() (using Windows functions GetFileTime() and SetFileTime()) are working, but SetFileTime fails if the file name contains Unicode characters. WHY???

Code: Select all

#Include once "windows.bi"
#Include once "vbcompat.bi"

Dim As Wstring * 500 file = "Text.txt"

''' GET FILE TIME: Unicode OK! Works for Textč.txt too!
''' ===================================================

Declare Function GetFileTimeW(file as Wstring, t As String = "w") As Double

Dim As String        t    = "w"
Dim As Double        tst

tst  = GetFileTimeW(file, t)

Print FORMAT(tst, "dd.mm.yyyy hh:mm:ss")

Function GetFileTimeW(file as Wstring, t As String = "w") As Double
  ' t (optional): letter c – create, a – access, or w – write
  ' Returns tst as SerialNumber
  Dim As FILETIME   ftCr, ftAc, ftWr
  Dim As SYSTEMTIME stUTC, stLo
  Dim As HANDLE     fh
  Dim As Double     tst
  fh  = CreateFileW(file, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0)
  GetFileTime(fh, @ftCr, @ftAc, @ftWr)
  If t = "c" Then FileTimeToSystemTime(@ftCr, @stUTC)
  If t = "a" Then FileTimeToSystemTime(@ftAc, @stUTC)
  If t = "w" Then FileTimeToSystemTime(@ftWr, @stUTC)
  SystemTimeToTzSpecificLocalTime(0, @stUTC, @stLo)
  tst = DATESERIAL(stLo.wYear, stLo.wMonth, stLo.wDay) + TIMESERIAL(stLo.wHour, stLo.wMinute, stLo.wSecond) 
  If stLo.wYear = 1601 Then tst = DATESERIAL(0, 1, 1)
  CloseHandle(fh)
  Return tst
End Function

' https://www.freebasic.net/forum/viewtopic.php?p=32365#p32365

''' SET FILE TIME: Unicode NOT OK! Doesn't work for Textč.txt!
''' ==========================================================

Declare Function SetFileTimeW(file as Wstring, tst As Double, t As String = "w") As Integer

tst = DATESERIAL(2012, 1, 1) + TIMESERIAL(12, 0, 0)      ' Set file date to 20120101 12:00:00

SetFileTimeW(file, tst, "caw")

Function SetFileTimeW(file as Wstring, tst As Double, t As String = "w") As Integer
  ' tst as SerialNumber
  ' t (optional): every combination of letters c – create, a – access, w – write
  Dim As SYSTEMTIME stLo, stUTC
  Dim As FILETIME   ft
  Dim As HANDLE     fh
  Dim As Integer    res
  stLo.wYear   = Year  (tst)
  stLo.wMonth  = Month (tst)
  stLo.wDay    = Day   (tst)
  stLo.wHour   = Hour  (tst)
  stLo.wMinute = Minute(tst)
  stLo.wSecond = Second(tst)
  TzSpecificLocalTimeToSystemTime(0, @stLo, @stUTC)
  SystemTimeToFileTime(@stUTC, @ft)
  fh  = CreateFile(file, FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0)
  If InStr(t, "c") Then res = SetFileTime(fh, @ft, 0  , 0  )
  If InStr(t, "a") Then res = SetFileTime(fh, 0  , @ft, 0  )
  If InStr(t, "w") Then res = SetFileTime(fh, 0  , 0  , @ft)
  CloseHandle(fh)
  Return res
End Function

/' Windows functions:
BOOL SetFileTime(
  HANDLE         hFile,
  const FILETIME *lpCreationTime,
  const FILETIME *lpLastAccessTime,
  const FILETIME *lpLastWriteTime
);
BOOL GetFileTime(
  HANDLE     hFile,
  LPFILETIME lpCreationTime,
  LPFILETIME lpLastAccessTime,
  LPFILETIME lpLastWriteTime
);
'/
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: FileDateTime() for Unicode

Post by Josep Roca »

> WHY???

Because you're using CreateFile instead of CreateFileW.
newbieforever
Posts: 117
Joined: Jun 21, 2018 11:14

Re: FileDateTime() for Unicode

Post by newbieforever »

Thanks, Josep...such a stupid typo...

This seems to be the final result of my request, which is transparent enogh to me as a newbie. Or are there suggestions to write the two functions more elegant?

Thanks to all here for your extraordinary help!!!

Code: Select all

#Include once "windows.bi"
#Include once "vbcompat.bi"
Declare Function GetFileTimeW(file as Wstring, t As String = "w") As Double
Declare Function SetFileTimeW(file as Wstring, tst As Double, t As String = "w") As Integer

Dim As Wstring * 500 file = "Textč.txt"

''' GET FILE TIME:
''' ==============

Dim As String        t    = "w"
Dim As Double        tst

tst  = GetFileTimeW(file, t)
Print FORMAT(tst, "dd.mm.yyyy hh:mm:ss")

Function GetFileTimeW(file as Wstring, t As String = "w") As Double
  ' t (optional): letter c – create, a – access, or w – write
  ' Returns tst as SerialNumber
  Dim As FILETIME   ftCr, ftAc, ftWr
  Dim As SYSTEMTIME stUTC, stLo
  Dim As HANDLE     fh
  Dim As Double     tst
  fh  = CreateFileW(file, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0)
  GetFileTime(fh, @ftCr, @ftAc, @ftWr)
  If t = "c" Then FileTimeToSystemTime(@ftCr, @stUTC)
  If t = "a" Then FileTimeToSystemTime(@ftAc, @stUTC)
  If t = "w" Then FileTimeToSystemTime(@ftWr, @stUTC)
  SystemTimeToTzSpecificLocalTime(0, @stUTC, @stLo)
  tst = DATESERIAL(stLo.wYear, stLo.wMonth, stLo.wDay) + TIMESERIAL(stLo.wHour, stLo.wMinute, stLo.wSecond) 
  If stLo.wYear = 1601 Then tst = DATESERIAL(0, 1, 1)
  CloseHandle(fh)
  Return tst
End Function

''' SET FILE TIME:
''' ==============

tst = DATESERIAL(2015, 1, 1) + TIMESERIAL(15, 0, 0)                         ' Set file date to 20150101 15:00:00

SetFileTimeW(file, tst, "caw")

Function SetFileTimeW(file as Wstring, tst As Double, t As String = "w") As Integer
  ' tst as SerialNumber
  ' t (optional): every combination of letters c – create, a – access, w – write
  Dim As SYSTEMTIME stLo, stUTC
  Dim As FILETIME   ft
  Dim As HANDLE     fh
  Dim As Integer    res
  stLo.wYear   = Year  (tst)
  stLo.wMonth  = Month (tst)
  stLo.wDay    = Day   (tst)
  stLo.wHour   = Hour  (tst)
  stLo.wMinute = Minute(tst)
  stLo.wSecond = Second(tst)
  TzSpecificLocalTimeToSystemTime(0, @stLo, @stUTC)
  SystemTimeToFileTime(@stUTC, @ft)
  fh  = CreateFileW(file, FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0)
  If InStr(t, "c") Then res = SetFileTime(fh, @ft, 0  , 0  )
  If InStr(t, "a") Then res = SetFileTime(fh, 0  , @ft, 0  )
  If InStr(t, "w") Then res = SetFileTime(fh, 0  , 0  , @ft)
  CloseHandle(fh)
  Return res
End Function


/' Windows functions:
BOOL SetFileTime(
  HANDLE         hFile,
  const FILETIME *lpCreationTime,
  const FILETIME *lpLastAccessTime,
  const FILETIME *lpLastWriteTime
);
BOOL GetFileTime(
  HANDLE     hFile,
  LPFILETIME lpCreationTime,
  LPFILETIME lpLastAccessTime,
  LPFILETIME lpLastWriteTime
);
'/
Post Reply