Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing file time stamp 3

Status
Not open for further replies.

coldan

Programmer
Oct 19, 2008
98
AU
In my app when I produce a report I copy the report files to a working folder and rename them 'myreport' etc

I would like to see that this has happened correctly by changing the myreport.frx and frt files to the current date/time.

I have tried the 'touch' procedure in the FAQ ( which I recognise from Linux playing years ago) but I am unable to get it working.

I call the procedure with


If File('myreport.frx')

touch('myreport.frx',DATE())
touch('myreport.frt',DATE())
endif

The FAQ states -
This code Requires the "Struct" class (available here: ) to be available to handle the API structures.

I have copied the given code into a prg ApiStructure.prg as suggested and have added

SET PROCEDURE TO ApiStructure.prg
before the OFS = CREATEOBJECT('OFSTRUCT') line in touch.prg

but it doesn't do the job - the file stamp remains the same.

Is there an easier way?

Can anyone help me here?

Coldan
 
Try this:
Code:
If File('myreport.frx')
   USE myreport.frx
   LOCATE FOR !EMPTY(expr)
   REPLACE expr WITH expr
   USE
endif
expr will have something in it in one of the records. Merely updating it with itself will update the .FRX and .FRT timestamp.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Code:
** Author:Cetin Basoz
Set Seconds On
Strtofile('Hello','test.txt')


* 'Touch' file datetime
* Sample - Set as if:
* Created 30 days before at 6 AM,
* Modified 10 days before at 5 AM
* set millisecs to 120 in all

_SetFileTime(Fullpath('test.txt'), ;
  Dtot(Date()-30)+3600*6,0,;
  Dtot(Date()-10)+3600*5,120)

Adir(aFileTime,'test.txt')
Disp Memo Like aFileTime

* Get millisecs using GetFileTime API if needed
* or you can use filer.dll to check all timings
Erase ('test.txt')

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

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

Function N2S
  Lparameters tnValue, tnSize
  Local lcStr, ix
  lcStr = ""
  For ix=1  To m.tnSize
    lcStr = m.lcStr + Chr(m.tnValue % 256)
    tnValue = Int(m.tnValue/256)
  Endfor
  Return m.lcStr


Cetin Basoz
MS Foxpro MVP, MCP
 
Use the pratically undocumented foxpro (foxtools) FoxTouch()
() function. One line of code.
Code:
SET LIBRARY TO foxtools.fll
 =FOXTOUCH( "myfile.txt", 1984, 2, 10, 13, 20, 6)


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 

Thanks to all

Mike,

I obviously like your one liner.
When I look for foxtouch() in the VFP helpfile it is not found. I had thought that foxtools functions had been include into VFP.

Do I need to add foxtools.fll to my project?

Coldan
 
PS Mike,

Where do I find a list of the parameters?

C
 
Hah! _ I've found foxtools chm but but foxtouch() doesn't appear to be in there - at least it's not found by a search.
 
Coldan,

Mike Gagnon gave you the parameters.

To recap, this is how you set the date modified to 7 Jan 2010, 12:00 :

Code:
SET LIBRARY TO HOME() + "FOXTOOLS.FLL"
FOXTOUCH("MyReport.FRX", 2010, 1, 7, 12, 0, 0)

Note that it is the date modified that is changed, not the date created or accessed.

You only need to do the SET LIBRARY once, not each time you call FOXTOUCH().

Hope this helps.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top