No announcement yet.

File Handle from filename-only?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Semen Matusovski
    William --
    test my training code (two or three monthes ago I found Dave's code and modified it a little)
    #Compile Exe
    #Register None
    #Include "WIN32API.INC"
    DefInt A-Z
    Function FileDateTime(ft As FileTime) As String
      Local st    As SystemTime
      Local zText As Asciiz * 255
      Local Temp  As String
      ' -- Convert the file time from UTC to local time
      FileTimeToLocalFileTime ft, ft
      ' -- Convert the file time into a compatible system time
      FileTimeToSystemTime ft, st
      ' -- Create a date string using the local settings
      GetDateFormat %LOCALE_USER_DEFAULT, %DATE_SHORTDATE, st, ByVal %NULL, zText, 255
      Temp = zText
      ' -- Create a time string using the local settings
      GetTimeFormat %LOCALE_USER_DEFAULT, %TIME_NOSECONDS, st, ByVal %NULL, zText, 255
      ' -- Return the file date and time
      Function = Temp + "  " + zText
    End Function
    Function PbMain
       Dim hFindFile As Long
       Dim lpFindFileData As WIN32_FIND_DATA
       hFindFile = FindFirstFile("C:\*.*", lpFindFileData)
       If hFindFile <> %INVALID_HANDLE_VALUE Then
             If (lpFindFileData.dwFileAttributes And &H18) <> 0 Then ' Directory / Label
                MsgBox lpFindFileData.cFileName + _
                   " Created " + FileDateTime$(lpFindFileData.ftCreationTime) + _
                   " LastAccess " + FileDateTime$(lpFindFileData.ftLastAccessTime) + _
                   " WriteTime = " + FileDateTime$(lpFindFileData.ftLastWriteTime) + _
                   " Attr = " + Str$(lpFindFileData.dwFileAttributes) + _
                   " Size = " + Str$(CDbl(lpFindFileData.nFileSizeHigh) * CDbl(&H10000) * CDbl(&H10000) + _
             End If
             If FindNextFile(hFindFile, lpFindFileData) = 0 Then Exit Do
          FindClose hFindFile
       End If
    End Function


    Leave a comment:

  • Eric Pearson
    William --

    A handle is only assigned (by Windows) when a file is opened.

    If you need a handle you'll need to use 1) the OpenFile API or 2) the PowerBASIC OPEN statement and the FILEATTR(,2) function to get the OS handle.

    -- Eric

    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:su[email protected][email protected]</A>

    [This message has been edited by Eric Pearson (edited February 08, 2000).]

    Leave a comment:

  • William Fletcher
    Guest started a topic File Handle from filename-only?

    File Handle from filename-only?

    I want to use the GetFileInformationByHandle Api to get dates and times on files out-of-the-blue by filename. This Api requires the file's handle, but I can't fathom where to establish it (the handle to the file).

    I am *not* creating the file or modifying it in *any* way - just want this info on files already on the hard drive (etc).

    Can anyone help?

    Many TIA.

    William Fletcher