FILE_DATE_TIME

 
Author Page created on Page updated on
Jacques Paris 25.04.06
 
DLL calls used by this example

Type tFileTime same as Type FILETIME

Type tSystemTime same as Type SYSTEMTIME

Type tWin32_Find_Data same as WIN32_FIND_DATA

FindFirstFile

FindNextFile

FindClose

FileTimeToLocalFileTime()

FileTimeToSystemTime()

 
Download available as:
 
MapBasic . Copy/Paste to a new MB page if needed, or download if available.

'This application prints to a dialog window the size (in bytes and KB)

'and the dates of last modification, last access and creation of the selected File.

'

'The selection is done by a FileOpenDlg requester.

'

'If the file extension is TAB, the user is given the choice of getting the output

'for the single file or for the entire set of files with that name. For the set, total

'size of all files, most recent dates among all files for corresponding types.

'Code developed from a listing offered on MapInfo-L (2002-08-16) by Frank Barret

'frankbarrett [frank@centroidsolutions.com] who writes that "it has been plagiarised!"

'largely from the Tabinfo.mbx available at

'http://www.acslink.aone.net.au/actaa/iaa13.htm.

'

'Other valuable input by Bill Thoen who does not know about it.

'

'Jacques Paris 2002-08-19 jacques@paris-pc-gis.com

'http://www.paris-pc-gis.com

'-----------------------------------

Type tFILETIME

    dwLowDateTime As Integer

    dwHighDateTime As Integer

End Type

Type tSYSTEMTIME

    wYear As SmallInt

    wMonth As SmallInt

    wDayOfWeek As SmallInt

    wDay As SmallInt

    wHour As SmallInt

    wMinute As SmallInt

    wSecond As SmallInt

    wMilliseconds As SmallInt

End Type

Type tWIN32_FIND_DATA

    dwFileAttributes As Integer

    ftCreationTime As tFileTime

    ftLastAccessTime As tFileTime

    ftLastWriteTime As tFileTime

    nFileSizeHigh As Integer

    nFileSizeLow As Integer

    dwReserved0 As Integer

    dwReserved1 As Integer

    cFileName As String * 260

    cAlternate As String * 14

End Type

 

Declare sub main

Declare Sub GetFileSizeAndTime(byVal strPattern as string, FileSize as float,

    ModifTime as tFILETIME, AccesTime as tFILETIME, CreatTime as tFILETIME)

Declare Sub GetSetSizeAndTime(byVal strPattern as string, FileSize as float, N_Files as smallint,

    ModifTime as tFILETIME, AccesTime as tFILETIME, CreatTime as tFILETIME)

Declare Function EncodeSystemTime(SystemTime As tSYSTEMTIME) as string

 

Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA"

   (ByVal lpFileName As String,

    lpFindFileData As tWIN32_FIND_DATA) As Integer

Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA"

   (ByVal hFindFile As Integer,

    lpFindFileData As tWIN32_FIND_DATA) As Integer

Declare Function FindClose Lib "kernel32" Alias "FindClose"

   (ByVal hFindFile As Integer) As Integer

Declare Function FileTimeToLocalFileTime Lib "kernel32" Alias "FileTimeToLocalFileTime"

   (lpFileTime As tFILETIME, lpLocalFileTime As tFILETIME) As Integer

Declare Function FileTimeToSystemTime Lib "kernel32" Alias "FileTimeToSystemTime"

   (lpFileTime As tFILETIME, lpSystemTime As tSYSTEMTIME) As Integer

 

dim gomult as logical

'------------------------------------------------------------------

Sub Main

'------------------------------------------------------------------

dim strPattern, strValue, strValue2, sfile, strValue2a, strValue2b, strValue2c as string

dim r as integer

dim nf as smallint

dim FileSize as float

dim UTCTimeStamp, ModTimeStamp, AccTimeStamp, CreTimeStamp as tFILETIME

dim LocalTimeStamp As tFILETIME

dim LocalDateTime As tSYSTEMTIME

sfile=fileopendlg("","","*.*","Select file to query")

if sfile="" then exit sub end if

if right$(sfile,3)="TAB" then

    gomult=ask("You selected a TAB file. Do you want info about that single file or for the whole file set?",

    "Whole Set","TAB only")

end if

if gomult then

    strPattern=Left$(sfile,Len(sfile)-4)+".*"

  else

    strPattern=sfile

end if

If gomult then

    Call GetSetSizeAndTime(strPattern,FileSize,nf,ModTimeStamp,AccTimeStamp,CreTimeStamp)

  else

    Call GetFileSizeAndTime(strPattern,FileSize,ModTimeStamp,AccTimeStamp,CreTimeStamp)

end if

' format file size

strValue=Format$(FileSize,"### ### ### ### ##0")+" bytes ("

+Format$(FileSize/1024,"### ### ### ##0")+" KB)"

r=FileTimeToLocalFileTime(ModTimeStamp,LocalTimeStamp)

r=FileTimeToSystemTime(LocalTimeStamp,LocalDateTime)

strValue2a=EncodeSystemTime(LocalDateTime)

r=FileTimeToLocalFileTime(AccTimeStamp,LocalTimeStamp)

r=FileTimeToSystemTime(LocalTimeStamp,LocalDateTime)

strValue2b=EncodeSystemTime(LocalDateTime)

r=FileTimeToLocalFileTime(CreTimeStamp,LocalTimeStamp)

r=FileTimeToSystemTime(LocalTimeStamp,LocalDateTime)

strValue2c=EncodeSystemTime(LocalDateTime)

if not gomult then

    dialog title "Selected Info for Single File"

    control statictext title "File Name : " position 5,5

    control statictext title strPattern position 10,15

    control statictext title "File Size : " + strValue position 5,35

    control statictext title "Last Access: " + strValue2b position 5,50

    control statictext title "Last Modif : " + strValue2a position 5,65

    control statictext title "Created on : " + strValue2c position 5,80

    control groupbox title "OpenWare from PPCC" position 5,110 width 250 height 40

    control statictext title "The code to this FileSelInfo.mbx can be obtained from" position 35,120

    control statictext title "jacques@paris-pc-gis.com if not found in the Kernel library" position 35,130

    control statictext title "http://www.paris-pc-gis.com/mb_r/dll_start.com" position 50,140

    control okbutton position 110,95

  else

    dialog title "Selected Info for Set of Files"

    control statictext title "Set Name : " position 5,5

    control statictext title strPattern position 10,15

    control statictext title "# of files in set : "+str$(nf) position 5,35

    control statictext title "Set Size : " + strValue position 5,50

    control statictext title "Most Recently Access : " + strValue2b position 5,65

    control statictext title "Most Recently Modif : " + strValue2a position 5,80

    control statictext title "Most Recently Created : " + strValue2c position 5,95

    control groupbox title "OpenWare from PPCC" position 5,125 width 250 height 40

    control statictext title "The code to this FileSelInfo.mbx can be obtained from" position 35,135

    control statictext title "jacques@paris-pc-gis.com if not found in the Kernel library" position 35,145

    control statictext title "http://www.paris-pc-gis.com/mb_r/dll_start.com" position 50,155

    control okbutton position 110,110

end if

end sub

 

'------------------------------------------------------------------

Sub GetFileSizeAndTime(byVal strPattern as string, FileSize as float,

ModifTime as tFILETIME, AccesTime as tFILETIME, CreatTime as tFILETIME)

'------------------------------------------------------------------

' for file identified by strPattern, returns file size and LastWrite time stamp

Dim intMBHandle As Integer

Dim intStatus as integer

Dim FileInfo As tWIN32_FIND_DATA

intMBHandle = FindFirstFile(strPattern, FileInfo)

if intMBHandle=-1 then

    note "Could not find handle for file : "+strPattern

end program

end if

if FileInfo.nFileSizeHigh=0 then

    FileSize=FileInfo.nFileSizeLow

  else

    FileSize=FileInfo.nFileSizeHigh*2^32 + FileInfo.nFileSizeLow

end if

ModifTime.dwHighDateTime=FileInfo.ftLastWriteTime.dwHighDateTime

ModifTime.dwLowDateTime=FileInfo.ftLastWriteTime.dwLowDateTime

AccesTime.dwHighDateTime=FileInfo.ftLastAccessTime.dwHighDateTime

AccesTime.dwLowDateTime=FileInfo.ftLastAccessTime.dwLowDateTime

CreatTime.dwHighDateTime=FileInfo.ftCreationTime.dwHighDateTime

CreatTime.dwLowDateTime=FileInfo.ftCreationTime.dwLowDateTime

' release memory block

intStatus= FindClose(intMBHandle)

End Sub

 

'------------------------------------------------------------------

Sub GetSetSizeAndTime(byVal strPattern as string, FileSize as float, N_Files as smallint,

ModifTime as tFILETIME, AccesTime as tFILETIME, CreatTime as tFILETIME)

'------------------------------------------------------------------

' for TABle identified by strPattern

' return sum of file sizes of all component files

' and return latest LastWrite time stamp of any component file

Dim intMBHandle As Integer

Dim intStatus as integer

Dim FileInfo As tWIN32_FIND_DATA

Dim intFileDate as Integer

Dim intFileTime as Integer

' init return values

FileSize=0

N_Files=0

ModifTime.dwLowDateTime=0

ModifTime.dwHighDateTime=0

AccesTime.dwLowDateTime=0

AccesTime.dwHighDateTime=0

CreatTime.dwLowDateTime=0

CreatTime.dwHighDateTime=0

' fetch info for first component file

intMBHandle = FindFirstFile(strPattern, FileInfo)

If intMBHandle = -1 Then

    note "Could not find handle for a component of "+stPattern

    end program

  else

' at least one file found

' repeat for each component file

    Do

' add component file size to total

        N_Files=N_Files+1

        if FileInfo.nFileSizeHigh=0 then

            FileSize=FileSize+FileInfo.nFileSizeLow

          else

        FileSize=FileSize+FileInfo.nFileSizeHigh*2^32 + FileInfo.nFileSizeLow

        end if

' save timestamp for component file if latest

        if (FileInfo.ftLastWriteTime.dwHighDateTime>ModifTime.dwHighDateTime) or

        ((FileInfo.ftLastWriteTime.dwHighDateTime=ModifTime.dwHighDateTime) and

        (FileInfo.ftLastWriteTime.dwLowDateTime>ModifTime.dwLowDateTime))then

            ModifTime.dwHighDateTime=FileInfo.ftLastWriteTime.dwHighDateTime

            ModifTime.dwLowDateTime=FileInfo.ftLastWriteTime.dwLowDateTime

        end if

        if (FileInfo.ftLastAccessTime.dwHighDateTime>AccesTime.dwHighDateTime) or

        ((FileInfo.ftLastAccessTime.dwHighDateTime=AccesTime.dwHighDateTime) and

        (FileInfo.ftLastAccessTime.dwLowDateTime>AccesTime.dwLowDateTime))then

            AccesTime.dwHighDateTime=FileInfo.ftLastAccessTime.dwHighDateTime

            AccesTime.dwLowDateTime=FileInfo.ftLastAccessTime.dwLowDateTime

        end if

        if (FileInfo.ftCreationTime.dwHighDateTime>CreatTime.dwHighDateTime) or

        ((FileInfo.ftCreationTime.dwHighDateTime=CreatTime.dwHighDateTime) and

        (FileInfo.ftCreationTime.dwLowDateTime>CreatTime.dwLowDateTime))then

            CreatTime.dwHighDateTime=FileInfo.ftCreationTime.dwHighDateTime

            CreatTime.dwLowDateTime=FileInfo.ftCreationTime.dwLowDateTime

        end if

        intStatus= FindNextFile(intMBHandle, FileInfo)

    Loop Until intStatus<>1

' release memory block

intStatus= FindClose(intMBHandle)

end if

End Sub

 

'------------------------------------------------------------------

Function EncodeSystemTime(SystemTime As tSYSTEMTIME) as string

'------------------------------------------------------------------

' convert Win API SystemTime structure to date-time string

EncodeSystemTime=

Format$(SystemTime.wDay,"00") + "-" +

Mid$("JanFebMarAprMayJunJulAugSepOctNovDec",(SystemTime.wMonth-1)*3+1,3) +"-" +

Format$(SystemTime.wYear ,"0000") + " " +

Format$(SystemTime.wHour,"00") + ":" +

Format$(SystemTime.wMinute,"00")

end function

 
Comments:

For create date/time of a single file, see the File_Date_Time example