Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Date of file
Message
From
30/05/2003 06:25:03
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
30/05/2003 02:56:49
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
00794382
Message ID:
00794416
Views:
10
This message has been marked as the solution to the initial question of the thread.
>HI there, I think to remember this question was already answered....
>anyway how can I programmatically change the last modified date of a file ?
>thank you again
>Alessio

Alessio,
You could do that with SetFileTime API.
(I don't remember the original creator of this file but I believe it was George Tasker or Larry Miller) :
lparameters tcFile, ttNewTime
DECLARE SHORT SetFileTime IN Win32API; 
  INTEGER hFile, STRING @lpftCreation,;
  STRING @lpftLastAccess, STRING @lpftLastWrite
DECLARE SHORT SystemTimeToFileTime IN Win32API;
  STRING @lpst,	STRING @lpft
DECLARE SHORT LocalFileTimeToFileTime IN Win32API;
  STRING @lpLocalFileTime, STRING @lpFileTime
DECLARE INTEGER CreateFile IN Win32API;
  STRING @lpFileName, INTEGER dwDesiredAccess,;
  INTEGER dwShareMode, STRING @lpSecurityAttributes,;
  INTEGER dwCreationDistribution, INTEGER dwFlagsAndAttributes,;
  INTEGER hTemplateFile
DECLARE SHORT CloseHandle IN Win32API;
  INTEGER hObject
#DEFINE GENERIC_WRITE    0x40000000
#DEFINE FILE_SHARE_WRITE 0x00000002
#DEFINE OPEN_EXISTING    0x00000003

lnhandle = CreateFile(@tcfile, GENERIC_WRITE, FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
lcreatetime = makefiletime(ttNewTime)
lnresult = SetFileTime(lnhandle, @lcreatetime, @lcreatetime, @lcreatetime)



FUNCTION MakeFileTime
LPARAMETER ltdate
LOCAL lnyear, lnmonth, lndow, lnday, lnhours,;
  lnminute, lnsecond, lnmilli, lnresult, lcresult
lnyear = YEAR(ltdate)
lnmonth = MONTH(ltdate)
lndow = DOW(ltdate,0)
lnday = DAY(ltdate)
lnhours = HOUR(ltdate)
lnminute = MINUTE(ltdate)
lnsecond = SEC(ltdate)
lnmilli = 0
lcsystime = Val2Str(lnyear, 2) + Val2Str(lnmonth, 2) +;
  Val2Str(lndow, 2) + Val2Str(lnday, 2) +;
  Val2Str(lnhours, 2) + Val2Str(lnminute, 2) +;
  Val2Str(lnsecond, 2) + Val2Str(lnmilli, 2)
STORE REPLICATE(CHR(0), 8) TO lcfiletime, lcutctime
lnresult = SystemTimeToFileTime(@lcsystime, @lcfiletime)
IF lnresult # 0
  lnresult = LocalFileTimeToFileTime(@lcfiletime, @lcutctime)
  IF lnresult # 0
    lcresult = lcutctime
  ENDIF
ENDIF
RETURN lcresult

FUNCTION Val2Str
LPARAMETERS pn_val, pn_bytes
LOCAL lcresult, lnval, lnmask, lni, lnbyte
lcresult = ""
lnval = pn_val
lnmask = 255
FOR lni = 1 TO pn_bytes
  lnbyte = BITAND(lnval, lnmask)
  lcresult = lcresult + CHR(lnbyte)
  lnval = BITRSHIFT(lnval, 8)
NEXT
RETURN lcresult
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform