Announcement

Collapse
No announcement yet.

Bug In DIR$ Command???

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

  • Bug In DIR$ Command???

    Why doesn't DIR$("C:\*.*", %ATTR_DIR) return only directories?? When
    I run the command and then test the result files using GETATTR the
    files are clearly not directories. Am I doing something wrong? Do I
    have to use FindFirstFile/FindNextFile APIs to retrieve only
    directories?

    ------------------
    Thanks,

    Doug Gamble
    mailto:[email protected][email protected]</A>
    Thanks,

    Doug Gamble
    [email protected]

  • #2
    That behavior is by design and is documented in DIR$:
    "If attribute is specified, it must use a standard operating system attribute code, causing DIR$ to include names of that attribute in the search, in addition to regular files."
    In other words, if you want to get a list containing just directories, you should test the attribute for each file, and exclude non-directory filenames. See GETATTR() for more information.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Or use the API, which is what I'm doing at the moment



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

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

      Comment


      • #4
        Let me throw a tip in that will save you a headache too, think Fred turned me onto this one:

        Do the findfile, findnext file (in a loop) and this is how I treat it:

        Code:
           Select Case Left$(FindData.cFileName,1)
                  Case "." 'Ignore these directories
                  Case "_" 'Front page directories
                  Case Else 'The critical one:
                        If Bit(FindData.dwFileAttributes, 4)=1 Then  '=> This is a folder (directory)
                          'Process, or do whatever
                        End If
           End Select
        ------------------
        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


        • #5
          I had a bit of trouble getting DIR$ to work in PBDLL so I followed
          the way I used it in PB35 and it worked okay.
          I think the PBDLL manual needs a bit more explanatory info.
          Regards,
          Brian


          ------------------
          Brian.

          Comment


          • #6
            Doug,
            Did you to consider to use this mask: "C:\*", combined with attrib-value 16? Directories don't have an extension (in most cases). This mask is searching for filenames without an extension.


            ------------------
            mailto:[email protected][email protected]</A>
            www.basicguru.com/zijlema/

            Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
            http://zijlema.basicguru.eu
            *** Opinions expressed here are not necessarily untrue ***

            Comment


            • #7
              Ugh! That is hardly a reliable method of operation, given that Long File Names and directories can contain many periods.

              For example:
              "C:\Program Files\MyApp Revision 1.2.3.123a\folder 1.2"


              ------------------
              Lance
              PowerBASIC Support
              mailto:[email protected][email protected]</A>
              Lance
              mailto:[email protected]

              Comment


              • #8
                BTW, FindFirstFile() is used internally by DIR$.



                ------------------
                Lance
                PowerBASIC Support
                mailto:[email protected][email protected]</A>
                Lance
                mailto:[email protected]

                Comment


                • #9
                  Correction Lance

                  FindFirstFileA() is used in DIR$

                  I'll never quit!!

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

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

                  Comment


                  • #10
                    Sorry Lance!

                    This was the way I did it in the good old days under DOS (8.3 filenames). You're right, it's unreliable under Windows.

                    ------------------
                    mailto:[email protected][email protected]</A>
                    www.basicguru.com/zijlema/

                    Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
                    http://zijlema.basicguru.eu
                    *** Opinions expressed here are not necessarily untrue ***

                    Comment

                    Working...
                    X