You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
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
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: