|
Add a comment to an Icetips Article
Please add your comments to this article.
Please note that you must provide both a name and a valid email address in order
for us to publish your comment. Comments are moderated and are not visible until they have been approved. Spam is never approved!
Back to article list
Search Articles
Add Comment
Printer friendly
Direct link
Par2: Getting file date and time without opening file - API call
1998-04-24 -- Todd Carlson
Getting Created, Modified and Last Accessed file date and time without
opening file - API call (Directory will not give created and last accessed
dates)
GetFileTime requires that you open the file, this code will do the same
thing, (and more) without opening the file, if you have the file open,
you should be able to use this as a guide to get GetFileTime working.
BTW - I just wrote this off the top of my head so I don't know if this will
compile or not, but I know the code is solid. Oh, it's 32bit only.
FILETIME GROUP,TYPE
dwLowDateTime DWORD
dwHighDateTime DWORD
END
WIN32_FIND_DATA GROUP,TYPE
dwFileAttributes DWORD
ftCreationTime GROUP(FILETIME).
ftLastAccessTime GROUP(FILETIME).
ftLastWriteTime GROUP(FILETIME).
nFileSizeHigh DWORD
nFileSizeLow DWORD
dwReserved0 DWORD
dwReserved1 DWORD
cFileName CSTRING( FILE:MaxFilePath )
cAlternateFileName CSTRING( 14 )
END
SYSTEMTIME GROUP,TYPE
wYear WORD
wMonth WORD
wDayOfWeek WORD
wDay WORD
wHour WORD
wMinute WORD
wSecond WORD
wMilliseconds WORD
END
CLAFILETIME GROUP,TYPE
FileDate LONG
FileTime LONG
END
INVALID_HANDLE_VALUE EQUATE(4294967295)
iFileName CSTRING(255)
iFileFind GROUP( WIN32_FIND_DATA ).
iFindHandle DWORD
iFileTime GROUP( CLAFILETIME ).
MAP
ConvertFileTime( FILETIME iTimeSource, *CLAFILETIME iTimeDest )
MODULE('WinAPI')
GetLastError(),DWORD,PASCAL,RAW,DLL(dll_mode)
FileTimeToSystemTime(*FILETIME lpFileTime, *SYSTEMTIME
lpSystemTime),BOOL,RAW,PASCAL,DLL(dll_mode),PROC
FileTimeToLocalFileTime(*FILETIME lpFileTime, *FILETIME
lpLocalFileTime),BOOL,RAW,PASCAL,DLL(dll_mode),PROC
FindFirstFile( *cSTRING lpFileName,
*WIN32_FIND_DATA ),HANDLE,RAW,PASCAL,DLL(dll_mode),NAME('FindFirstFileA')
FindClose( HANDLE hFindFile ),BOOL,RAW,PASCAL,dll(dll_mode),PROC
END
END
CODE
iFindHandle = ZERO
iFileName = 'C:\AUTOEXEC.BAT'
iFindHandle = FindFirstFile( iFileName, iFileFind )
IF iFindHandle = INVALID_HANDLE_VALUE
STOP( 'Unable to find File!' )
FindClose( iFindHandle )
RETURN
ELSE
CLEAR( iFileTime )
ConvertFileTime( iFileFind.ftCreationTime, iFileTime )
STOP( 'File was Created - ' & FORMAT( iFileTime.FileDate, @d3 ) & ' @ '
& FORMAT( iFileTime.FileTime, @T4 ) )
ConvertFileTime( iFileFind.ftLastAccessTime, iFileTime )
STOP( 'File was Last Accessed - ' & FORMAT( iFileTime.FileDate, @d3 ) &
' @ ' & FORMAT( iFileTime.FileTime, @T4 ) )
ConvertFileTime( iFileFind.ftWriteTime, iFileTime )
STOP( 'File was Written- ' & FORMAT( iFileTime.FileDate, @d3 ) & ' @ ' &
FORMAT( iFileTime.FileTime, @T4 ) )
FindClose( iFindHandle )
END
RETURN
ConvertFileTime PROCEDURE( *FILETIME iTimeGroup,
*CLAFILETIME iTimeDest )
iTempLocalTime GROUP(FILETIME).
iTempSystemTime GROUP(SYSTEMTIME).
CODE
FileTimeToLocalFileTime( iTimeGroup, iTempLocalTime )
FileTimeToSystemTime( iTempLocalTime, iTempSystemTime )
iTimeDest.FileDate = DEFORMAT( iTempSystemTime.wMonth & '/' &
iTempSystemTime.wDay & '/' & iTempSystemTime.wYear, @d2 )
iTimeDest.FileTime = DEFORMAT( iTempSystemTime.wHour & ':' &
iTempSystemTime.wMinute & ':' & iTempSystemTime.wSecond, @t4 )
RETURN
Carl Barnes notes:
WORD is normallay ULONG but in this case its USHORT so the code should be:
SYSTEMTIME GROUP,TYPE !System time struct
wYear USHORT
wMonth USHORT
wDayOfWeek USHORT
wDay USHORT
wHour USHORT
wMinute USHORT
wSecond USHORT
wMilliseconds USHORT
END
Today is November 21, 2024, 7:27 am This article has been viewed 35221 times.
Back to article list
Search Articles
Add Comment
Printer friendly
|
|
|