Get File(Time)Information

This class gives you information about
FileSize, FileAttributes, LastAccessed, LastModified etc.

'Sample usage:

Sub Click(Source As Button)

Const LAST_ACCESS = 0
Const LAST_WRITE = 1
Const CREATION_TIME = 2
Const EIGHT_THREE_NAME = 3
Const FILE_SIZE = 4
Const FILE_NAME = 5
Const FILE_ATTRIBUTES = 6

Dim FI As New FileInfo

File$ = "c:\mpie4ful.exe"

Msgbox FI.GetFileTimeInfo ( File$ , LAST_ACCESS )
Msgbox FI.GetFileInfo ( File$ , FILE_SIZE )

End Sub
' Put this code into the declaration section

Const INVALID_HANDLE_VALUE = -1
Const MAX_PATH = 260

Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Type WIN32_FIND_DATA
dwFileAttributes As Long ' Dateiattribute
ftCreationTime As FILETIME ' Erstellungsdatum
ftLastAccessTime As FILETIME ' Letzter Zugriff
ftLastWriteTime As FILETIME ' Letzte Speicherung
nFileSizeHigh As Long ' Gr??e (Hi)
nFileSizeLow As Long ' Gr??e (Lo)
dwReserved0 As Long ' bedeutungslos
dwReserved1 As Long ' bedeutungslos
cFileName As String * MAX_PATH ' Dateiname
cAlternate As String * 14 ' 8.3-Dateiname
End Type

Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type


Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As
FILETIME, lpLocalFileTime As FILETIME) As Long
Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (Byval
lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (Byval
hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Declare Function FindClose Lib "kernel32" (Byval hFindFile As Long) As Long
Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME,
lpSystemTime As SYSTEMTIME) As Long
Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As
SYSTEMTIME, lpFileTime As FILETIME) As Long

Class FileInfo

Public Function GetFileTimeInfo ( strPath As String , MODE As Integer ) As
String

Dim FileHandle As Long
Dim FileData As WIN32_FIND_DATA
Dim LocalFileTime As FILETIME
Dim LocalSystemTime As SYSTEMTIME

FileHandle = FindFirstFile(strPath & vbNullChar, FileData)
Select Case MODE

Case 0
FileTimeToLocalFileTime FileData.ftLastAccessTime,
LocalFileTime
Case 1
FileTimeToLocalFileTime FileData.ftLastWriteTime,
LocalFileTime
Case 2
FileTimeToLocalFileTime FileData.ftCreationTime,
LocalFileTime

End Select

FileTimeToSystemTime LocalFileTime, LocalSystemTime

GetFileTimeInfo = _
Left$(FileData.cFileName, Instr(FileData.cFileName, vbNullChar) - 1)
_
& LocalSystemTime.wDay & "." _
& LocalSystemTime.wMonth & "." _
& LocalSystemTime.wYear & ", "_
& LocalSystemTime.wHour & ":" _
& Format$(LocalSystemTime.wMinute, "00") _
& ":" & Format$(LocalSystemTime.wSecond, "00") & " Uhr"

FindClose FileHandle

End Function

Public Function GetFileInfo ( strPath As String , MODE As Integer ) As
String

Dim FileHandle As Long
Dim FileData As WIN32_FIND_DATA

FileHandle = FindFirstFile ( strPath & vbNullChar , FileData )

If FileHandle <> INVALID_HANDLE_VALUE Then

Select Case MODE

Case 3
GetFileInfo = FileData.cFileName
Case 4
GetFileInfo = Cstr(FileData.nFileSizeLow)
Case 5
GetFileInfo = FileData.cFileName
Case 6
GetFileInfo = Cstr(FileData.dwFileAttributes)

End Select
End If
FindClose FileHandle

End Function

End Class
This was first published in November 2000

Dig deeper on Domino Resources

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close