Announcement

Collapse
No announcement yet.

Dir$

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

  • Dir$

    Is DIR$ and DIR$(NEXT) substitute for FindFirstFile() and FindNextFile()?
    My test program provides different results!?

    Code:
    '#COMPILER PBWIN 9.0x
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "WIN32API.INC"
    
    GLOBAL gcFolders    AS LONG
    GLOBAL gcFiles      AS LONG
    
    SUB TEST_FindFile (BYVAL sStartFolder AS STRING)
    LOCAL hSearch  AS DWORD
    LOCAL WFD      AS WIN32_FIND_DATA
        sStartFolder = RTRIM$(sStartFolder, "\")
        hSearch = FindFirstFile(BUILD$(sStartFolder,"\*.*"), WFD)
        IF hSearch <> %INVALID_HANDLE_VALUE THEN
            DO
                IF (WFD.dwFileAttributes AND %FILE_ATTRIBUTE_DIRECTORY) = %FILE_ATTRIBUTE_DIRECTORY THEN
                    IF WFD.cFileName <> "." AND WFD.cFileName <> ".." THEN
                        INCR gcFolders
                        CALL TEST_FindFile (sStartFolder + "\" + WFD.cFileName)
                    END IF
                ELSE
                    INCR gcFiles
                END IF
            LOOP WHILE FindNextFile(hSearch, WFD)
            FindClose hSearch
        END IF
    END SUB
    
    SUB TEST_PBDIR (BYVAL sStartFolder AS STRING)
    LOCAL sSearch  AS STRING
    LOCAL WFD      AS DIRDATA
        sStartFolder = RTRIM$(sStartFolder, "\")
        sSearch = DIR$(BUILD$(sStartFolder,"\*.*"), TO WFD)
        IF sSearch <> "" THEN
            DO
                IF (WFD.FileAttributes AND %SUBDIR) = %SUBDIR THEN
                    IF WFD.FileName <> "." AND WFD.FileName <> ".." THEN
                        INCR gcFolders
                        CALL TEST_PBDIR (sStartFolder + "\" + WFD.FileName)
                    END IF
                ELSE
                    INCR gcFiles
                END IF
                sSearch = DIR$(NEXT)
            LOOP WHILE LEN(sSearch)
            DIR$ CLOSE
        END IF
    END SUB
    
    FUNCTION PBMAIN () AS LONG
    LOCAL StartFolder AS STRING
    LOCAL tmp AS STRING
    LOCAL i AS LONG
    
        DIM gsErr(0) AS STRING
        
        StartFolder = COMMAND$ : IF LEN(StartFolder) < 1 THEN StartFolder = "C:\Windows"
        
        GOTO TEST1
        
        
    TEST1:
        gcFolders  = 0
        gcFiles    = 0
        CALL TEST_FindFile (StartFolder)
        ' --------------------------------------------------------------------------------
        tmp = tmp + $CR + "FindFirstFile(), FindNextFile()" + $CR + _
              "-------------------------------------------------------" + $CR + _
              FORMAT$(gcFolders) + " subfolders in " + StartFolder + $CR + _
              "Files:        " + FORMAT$(gcFiles) + $CR + $CR
        ' ================================================================================
        
    
    TEST2:
        gcFolders  = 0
        gcFiles    = 0
        CALL TEST_PBDIR (StartFolder)
        ' --------------------------------------------------------------------------------
        tmp = tmp + $CR + "DIR$(), DIR$(NEXT)" + $CR + _
              "-------------------------------------------------------" + $CR + _
              FORMAT$(gcFolders) + " subfolders in " + StartFolder + $CR + _
              "Files:        " + FORMAT$(gcFiles)
        ' ================================================================================
        
        
        MSGBOX tmp
    END FUNCTION

  • #2


    I had misread the description in the Help file.
    There is no problem with the function DIR$.

    Comment

    Working...
    X