Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

changing file time stamp

changing file time stamp

changing file time stamp

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')


The FAQ states -
  This code Requires the "Struct" class (available here: http://fox.wikis.com/wc.dll?Wiki~ApiStructureClass )  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?


RE: changing file time stamp

Try this:


If File('myreport.frx')
   USE myreport.frx
   REPLACE expr WITH expr
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-  
Even more Fox stuff at:

RE: changing file time stamp


** Author:Cetin Basoz
Set Seconds On

* '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'), ;

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(ttModify),0,Time2FileTime(m.ttModify,m.tnMillisecs))) && Set file times
    =CloseHandle(m.lnHandle) && Close the handle
  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
  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)
  Return m.lcStr

Cetin Basoz
MS Foxpro MVP, MCP

RE: changing file time stamp


Thanks to all


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?


RE: changing file time stamp

PS Mike,

Where do I find a list of the parameters?


RE: changing file time stamp

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.

RE: changing file time stamp


Mike Gagnon gave you the parameters.

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


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 Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business

RE: changing file time stamp

Thanks to both Mikes!


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close