Announcement

Collapse
No announcement yet.

When is a Directory not a Directory?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • When is a Directory not a Directory?

    When it's a system Directory??

    below is the File attribute parameters from the latest win32api.inc

    %FILE_ATTRIBUTE_READONLY = &H1
    %FILE_ATTRIBUTE_HIDDEN = &H2
    %FILE_ATTRIBUTE_SYSTEM = &H4
    %FILE_ATTRIBUTE_DIRECTORY = &H10
    %FILE_ATTRIBUTE_ARCHIVE = &H20
    %FILE_ATTRIBUTE_NORMAL = &H80
    %FILE_ATTRIBUTE_TEMPORARY = &H100
    %FILE_ATTRIBUTE_COMPRESSED = &H800

    But when I call a list of Files from C drive on Win2k the "C:\WINNT\" directory
    doesn't get flagged as a directory and neither does "Program Files".

    C:\WINNT is getting Flagged with &H30 and
    C:\Program Files is getting Flagged with &H31

    Why?? and are there any other's I need to look out for??.

    Here's some demo code: (I'm just outputting to msgbox's at the moment to test the output vals

    Code:
    #Compile Exe
    #Include "win32api.inc"
    
    Declare Function findfilesapi(DirPath As String, FileSpec As String) As Long
    
    Global CurrentFile As Long
    Global FileArray() As String
    
    
    Function PbMain() As Long
          ReDim FileArray(200) As String
          Dim x As Long
          Dim MsgString As String
          Dim Retval As Long
    
          CurrentFile = 1
          Retval = findfilesapi("c:\", "*.*")
    
          For x = 1 To currentfile
            MsgString = Msgstring & FileArray(x) & $CRLF
          Next
    
        MsgBox msgstring
    
    
    End Function
    
    
    Function findfilesapi(DirPath As String, FileSpec As String) As Long
    
    Dim FindData As WIN32_FIND_DATA
    Dim FindHandle As Long
    Dim FindNextHandle As Long
    Dim filestring As String
    
    DirPath = Trim$(DirPath)
    
    If Right$(DirPath, 1) <> "\" Then
      DirPath = DirPath & "\"
    End If
    
    ' Find the first file in the selected directory
    
    FindHandle = FindFirstFile(DirPath & FileSpec, FindData)
    If FindHandle <> 0 Then
      If FindData.dwFileAttributes = %FILE_ATTRIBUTE_DIRECTORY Then
        ' It's a directory
        If Left$(FindData.cFileName, 1) <> "." And Left$(FindData.cFileName, 2) <> ".." Then
          filestring = DirPath & Trim$(FindData.cFileName) & "\"
          FileArray(CurrentFile) = "DIR " & filestring
          Incr CurrentFile
        End If
      Else
        filestring = DirPath & Trim$(FindData.cFileName)
        FileArray(CurrentFile) = filestring
         Incr CurrentFile
      End If
    End If
    
    ' Now loop and find the rest of the files
    If FindHandle <> 0 Then
      Do
          
        FindNextHandle = FindNextFile(FindHandle, FindData)
        If FindNextHandle <> 0 Then
          If FindData.dwFileAttributes = %FILE_ATTRIBUTE_DIRECTORY Then
            ' It's a directory
            If Left$(FindData.cFileName, 1) <> "." And Left$(FindData.cFileName, 2) <> ".." Then
              filestring = DirPath & Trim$(FindData.cFileName) & "\"
              FileArray(CurrentFile) = "DIR " & filestring
              Incr CurrentFile
            End If
          Else
            filestring = DirPath & Trim$(FindData.cFileName)
            If filestring = "c:\Program Files" Then MsgBox filestring & Hex$(FindData.dwFileAttributes)
            FileArray(CurrentFile) = filestring
            Incr CurrentFile
          End If
        Else
          Exit Do
        End If
      Loop
    End If
    
    Call FindClose(FindHandle)
    
    findfilesapi = 1
    
    End Function
    ------------------

    Paul Dwyer
    Network Engineer
    Aussie in Tokyo
    (Paul282 at VB-World)

  • #2
    Well, FILE_ATTRIBUTE_DIRECTORY is not an exclusive flag
    It can be combined with most of the other flags.
    Revise your code and you will find the answer
    A directory is not a directory (you should access) if flag
    FILE_ATTRIBUTE_TEMPORARY is set
    ---
    Hint:
    If FindData.dwFileAttributes = %FILE_ATTRIBUTE_DIRECTORY Then

    ------------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se



    [This message has been edited by Fred Oxenby (edited February 07, 2001).]
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

    Comment


    • #3
      Fred,

      I thought about that and thought maybe I should use AND instead of "=" for that but then all the files mark as directories.

      how can I flag just the directories?

      ------------------

      Paul Dwyer
      Network Engineer
      Aussie in Tokyo
      (Paul282 at VB-World)

      Comment


      • #4
        Code:
        If (FindData.dwFileAttributes AND %FILE_ATTRIBUTE_DIRECTORY) = _
               %FILE_ATTRIBUTE_DIRECTORY
        I think that will do it .. or you can test the correct bit.

        Mike

        ------------------

        Comment


        • #5
          Thank you both, That worked.

          it was a case of "Close, but no cigar" for me and I needed a push.

          Cheers

          ------------------

          Paul Dwyer
          Network Engineer
          Aussie in Tokyo
          (Paul282 at VB-World)

          Comment


          • #6
            See my other post, might save you a few lines of code, I did the ".." thing too, but it was flaky...
            Test hte left character, for "." and "_" (Front page directories), otherwise take bit 4 as in my other exmample to your other post

            Again I think Fred was the master on that one...

            Scott

            ------------------
            Scott
            mailto:[email protected][email protected]</A>
            Scott Turchin
            MCSE, MCP+I
            http://www.tngbbs.com
            ----------------------
            True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

            Comment


            • #7
              Originally posted by Paul Dwyer:
              I thought about that and thought maybe I should use AND instead of "=" for that but then all the files mark as directories.
              With IF statements, it is important to keep in mind that PowerBASIC treats
              AND as a Boolean operation by default, not as a bitwise operation. This is
              to allow for early-out optimization. If you need a bitwise AND in an IF
              statement, just enclose the entire conditional in parenthesis:
              Code:
              If (FindData.dwFileAttributes AND %FILE_ATTRIBUTE_DIRECTORY) Then

              ------------------
              Tom Hanlin
              PowerBASIC Staff

              Comment

              Working...
              X