File date and time

topic: 

Code below shows how to retrieve file date and time using native VFP commands or WSH. For Windows API based solution that also allows to set file date and time, see George Tasker's Windows Time hosted on UT

MSDN links:
This is sample code. Add error handling and adjust to your requirements as necessary.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21

* VFP - Last Modified only
#DEFINE ccADIR_NAME 1
#DEFINE ccADIR_SIZE 2
#DEFINE ccADIR_DATE 3
#DEFINE ccADIR_TIME 4
#DEFINE ccADIR_ATTR 5

lcFileName = "test.txt"
DIMENSION laFleInfo[1]
= ADIR(laFleInfo, lcFileName)
* Date and Time Modified 
? "ADIR: ", laFleInfo[ccADIR_DATE], laFleInfo[ccADIR_TIME]
* Date Modified 
? "FDATE: ", FDATE(lcFileName)
* Time Modified 
? "FTIME: ",FTIME(lcFileName)
* DateTime Modified 
? "FDATE,1: ", FDATE(lcFileName,1)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12

* WSH
* Full path is required
lcFileName = FULLPATH("test.txt")
loFSO = CREATEOBJECT("Scripting.FileSystemObject")
loFile = loFSO.GetFile(lcFileName)
WITH loFile
	? .DateLastModified, .DateCreated, .DateLastAccessed
ENDWITH	


Comments

Cool code, I just would like to note that your 2nd example using WSH will not work on a 64 Bit OS like Vista ... I have been looking for a WSH 64 Bit version with no luck. Microsoft is no longer supports classic ASP witch was one of the primary users of WSH. They would like you to move to .Net. There's for no reason for them to build a 64 Bit version. If anyone knows otherwise please let me know. My copy of UnitFox testing tool will no long work for that reason and I would like to fix it.


Can you be more specific about the problem? 64-bit Vista and Windows 7 have both (32-bit and 64-bit) WSH versions installed.

Works for my installation on Windows 7 Pro 64 bit and VFP9. Thanks for the tip. I am loving WSH.

Second code is fine .,, it helped in identifying the availability of new version on net.