File date and time

Tagged:

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 http://www.UniversalThread.com.

MSDN links:
WSH FileSystemObject Object
WSH File Object

This is sample code. Add error handling and adjust to your requirements as necessary.

&& VFP - Last Modified only
#DEFINE ADIR_NAME 1
#DEFINE ADIR_SIZE 2
#DEFINE ADIR_DATE 3
#DEFINE ADIR_TIME 4
#DEFINE ADIR_ATTR 5
lcFileName = "test.txt"
DIMENSION laFleInfo[1]
= ADIR(laFleInfo, lcFileName)
&& Date and Time Modified 
? laFleInfo[ADIR_DATE], laFleInfo[ADIR_TIME]
&& Date Modified 
? FDATE(lcFileName)
&& Time Modified 
? FTIME(lcFileName)
&& Date and Time Modified 
? FDATE(lcFileName,1)
 
&&-----------------------------------------
&& WSH
&& Full path is required
lcFileName = FULLPATH("test.txt")
loFSO = CREATEOBJECT("Scripting.FileSystemObject")
loFile = loFSO.GetFile(lcFileName)
? loFile.DateLastModified, loFile.DateCreated, loFile.DateLastAccessed