Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to address files on disk with same name as enclosed
Message
From
02/09/2003 06:17:08
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
01/09/2003 22:54:21
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00825164
Message ID:
00825215
Views:
16
>Hi,
>
>While writing a program to update customers' app and data files' structure, I've come across some issues:
>
>If a file is included in the executable, is there any way to refer to a file with the same name that is on disk? A workaround is to rename internal files, but because my tables are encrypted problems (inconveniences, really) arise. Any suggestions?
>
>Also, is there a way to set the "date modified" of a file?
>
>TIA,
>
>Alex

Alex,
You could use a fullpath for the file on disk.
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)
  	&& Created 30 days before 6 AM, Modified 10 days before,5 AM
  Adir(aFileTime,"test.txt")
*  Erase test.txt
  Disp Memo Like aFileTime
Endif

Function _SetFileTime
Lparameters tcFile, ttCreate, ttAccess, ttModify

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)),;
  Iif(Empty(ttAccess),0,Time2FileTime(ttAccess)),;
  Iif(Empty(ttModify),0,Time2FileTime(ttModify))) && Set file times
  =CloseHandle(lnHandle) && Close the handle
Endif
Return (lnresult # 0)

Function Time2FileTime
Lparameter ttDateTime
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(0, 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