Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Change a File Date Modified
Message
From
25/03/2005 10:38:56
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
25/03/2005 10:03:40
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 7
Miscellaneous
Thread ID:
00999140
Message ID:
00999152
Views:
29
>Hi All,
>I want to be able to change a files (header?) to reflect
>a different date. Used to do this w/XTREE Gold way back
>when But now? Wscript host? Low level I/O?
>Any snippet available?
>Thanks.
Set Seconds on
handle=Fcreate("test.txt")
If handle > 0
  =Fwrite(handle,"Hello",5)
  =Fclose(handle)
  
  _SetFileTime(Sys(5)+Curdir()+"test.txt", ;
  	Dtot(Date()-30)+3600*6,;
  	0,;
  	Dtot(Date()-10)+3600*5, ;
  	120)
  	&& Created 30 days before 6 AM, Modified 10 days before,5 AM
  	&& all millisecs = 120
  Adir(aFileTime,"test.txt")
  Disp Memo Like aFileTime
  
  * Get millisecs using GetFileTime
 * GetFileTimes('Test.txt')
  Erase test.txt
Endif

Function _SetFileTime
Lparameters tcFile, ttCreate, ttAccess, ttModify, tnMillisecs

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

Local lnResult, lnHandle
lnResult = 0
lnHandle = CreateFile(@tcFile, GENERIC_WRITE, FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0) && Create handle
If lnHandle > 0
  lnResult = SetFileTime(lnHandle, ;
  Iif(Empty(ttCreate),0,Time2FileTime(ttCreate,tnMillisecs)),;
  Iif(Empty(ttAccess),0,Time2FileTime(ttAccess,tnMillisecs)),;
  Iif(Empty(ttModify),0,Time2FileTime(ttModify,tnMillisecs))) && Set file times
  =CloseHandle(lnHandle) && Close the handle
Endif
Return (lnresult # 0)

Function Time2FileTime
Lparameter ttDateTime, tnMillisecs
tnMillisecs = Iif(Empty(tnMillisecs), 0, tnMillisecs)
Local lcresult, lcSysTime, lcFileTime, lcUTCtime
lcresult = ''
lcSysTime = N2S(Year(ttDateTime), 2) + ;
  N2S(Month(ttDateTime), 2) +;
  N2S(Dow(ttDateTime), 2) + ;
  N2S(Day(ttDateTime), 2) +;
  N2S(Hour(ttDateTime), 2) +;
  N2S(Minute(ttDateTime), 2) +;
  N2S(Sec(ttDateTime), 2) + ;
  N2S(tnMillisecs, 2)
Store Replicate(Chr(0), 8) To lcfiletime, lcUTCtime
If ( SystemTimeToFileTime(@lcSysTime, @lcFileTime) # 0 ) And ;
    ( LocalFileTimeToFileTime(@lcFiletime, @lcUTCtime) # 0 )
  lcResult = lcUTCtime
Endif
Return lcresult

Function N2S
Lparameters tnValue, tnSize
Local lcStr, ix
lcStr = ""
For ix=1  To tnSize
  lcStr = lcStr + Chr(tnValue % 256)
  tnValue = Int(tnValue/256)
Endfor
Return lcStr
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