#Include once "window9.bi"

Dim Shared As WIN32_FIND_DATA FileInformation

Function ExamineDirectory(ByVal DirectoryName As string,ByVal Pattern As string) As Integer Export
  Var strPattern = DirectoryName + Pattern
  Return Cast(Integer,FindFirstFile(strPattern, @FileInformation))
End Function

Function NextDirectoryEntry(ByVal HandleDirectory As integer) As Integer Export
  Return FindNextFile(Cast(HANDLE,HandleDirectory), @FileInformation)
End Function

Function DirectoryEntryAttributes(ByVal  HandleDirectory As integer) As Integer Export
  Return FileInformation.dwFileAttributes
End Function

Function FinishDirectory(ByVal HandleDirectory As integer) As Integer Export
  Return FindClose(Cast(HANDLE,HandleDirectory))
End Function

Function DirectoryEntrySize(ByVal HandleDirectory As integer) As ULongInt Export
  Return CULngInt( cuLngInt(FileInformation.nFileSizeLow) or (CULngInt(FileInformation.nFileSizeHigh) shl 32) )
End Function

Function DirectoryEntryDate(ByVal HandleDirectory As Integer , ByVal flag As Integer) As String Export
  Dim As FILETIME fttime
  Dim As FILETIME ftlocal
  Dim As SYSTEMTIME SYS_TIME
  Dim As String hour_,minute_,second_,month_,Day_
  Select Case flag
    Case 1
      fttime=FileInformation.ftCreationTime
    Case 2
      fttime=FileInformation.ftLastAccessTime
    Case 3
      fttime=FileInformation.ftLastWriteTime
  End Select

  FileTimeToLocalFileTime(@fttime,@ftlocal)
  FileTimeToSystemTime(@ftlocal,@SYS_TIME)
  If SYS_TIME.wday<10 Then
    Day_="0" & SYS_TIME.wday
  Else
    Day_=Str( SYS_TIME.wday)
  EndIf
  If SYS_TIME.wmonth<10 Then
    month_="0" & SYS_TIME.wmonth
  Else
    month_=Str( SYS_TIME.wmonth)
  EndIf
  If SYS_TIME.whour<10 Then
    hour_="0" & SYS_TIME.whour
  Else
    hour_=Str( SYS_TIME.whour)
  EndIf
  If SYS_TIME.wminute<10 Then
    minute_="0" & SYS_TIME.wminute
  Else
    minute_=Str( SYS_TIME.wminute)
  EndIf
  If SYS_TIME.wsecond<10 Then
    second_="0" & SYS_TIME.wsecond
  Else
    second_=Str(SYS_TIME.wsecond)
  EndIf
  Return day_ & "." & month_ & "." & SYS_TIME.wyear & " " & hour_ & ":" & minute_ & ":" & second_
End Function

Function DirectoryEntryName(ByVal  HandleDirectory As integer) As string Export
  Return FileInformation.cFileName
End Function
