Post by Walt Decker on Feb 3, 2021 15:41:17 GMT -5
If you have multiple storage devices this might be handy.
DIR_FUNCTIONS.ZIP (34.75 KB)
'
ERR.SUCCESS = -1
ERR.NOT.INITIALIZED = -1000
ERR.NOMORE.ENTRIES = -1001
ERR.PATH.NOT.FOUND = -1002
ERR.NO.PATHS.FOUND = -1003
ERR.BUFFER.TO.SMALL = -1004
ERR.FILE.NOT.FOUND = -1005
ERR.NO.FILES.FOUND = -1006
ERR.IS.FOLDER = -1007
ERR.BAD.PARAMETER = -1008
'ENUM ExeType
EXE.INST = 1 ' This returns the instance handle (a DWord)
'of the program which is currently executing.
EXE.EXTN = 2 ' This returns the extension (with a leading period)
'of the program which is currently executing.
EXE.FULL = 3 ' This returns the complete drive, path, file name, and
'extension of the program which is currently executing.
EXE.NAME = 4 ' This returns just the file name of the program which
'is currently executing.
EXE.NAMEEX = 5 ' This returns the file name and the extension of the
'program which is currently executing.
EXE.PATH = 6 ' This returns the complete drive and path of the
'program which is currently executing
'END ENUM
MaxPath = 260
C0$ = CHR$(0)
'DIM Drives$(0)
'OPEN "e:\pbwin10\dlls\FN_Dir" FOR DLL AS #DIR
OPEN "FN_Dir" FOR DLL AS #DIR
'/===================================================================================/'
' NOTE!!!
'/===================================================================================/'
' THESE FUNCTIONS WILL ONLY WORK
' ON THE LOCAL COMPUTER. THE WILL NOT
' WORK OVER A LAN(LOCAL AREA NETWORK)
' OR THE INTERNET
'/===================================================================================/'
' THE "_Init" FUNCTIONS RE-INITIALIZE THEIR DATA EACH TIME THEY ARE CALLED.
' THE "_GetNext" FUNCTIONS WILL RETRIEVE DATA UNTIL THEN END.
' IF YOU WANT TO CHANGE PARAMETERS YOU MUST CALL THE APPROPRIATE "_Init" FUNCTION
' OTHERWISE YOU WILL RECEIVE INAPPROPRIATE DATA WHEN YOU NEXT CALL ONE OF THE
' "_GetNext" FUNCTIONS
'/===================================================================================/'
CALLDLL #DIR, "FN_InitDrives", _ '<--- Enumerates the number of
_ 'storage devices on your computer
NumDrvs AS LONG 'RETURN: Number of devices found
PRINT NumDrvs
Drv$ = SPACE$(MaxPath) + C0$
CALLDLL #DIR, "FN_GetNextDrive", _ '<--- Gets each succeding device
Drv$ AS STRUCT, _ '<--- RETURN: Device letter with ":"
_ 'attached
RetVal AS LONG '<--- RETURN: One-based index of
'<--- device OR ERR.NOMORE.ENTRIES
PRINT Drv$
Drv$ = "C:\" + C0$
CALLDLL #DIR, "FN_ChangeDir", _ '<--- Changes directory
Drv$ AS STRUCT, _ '<--- Directory(folder) path
RetVal AS LONG _ '<--- RETURN: ERR.SUCCESS or
'ERR.PATH.NOT.FOUND
PRINT RetVal
CALLDLL #DIR, "FN_GetCurrentPath", _ '<--- Gets directory(folder)
Drv$ AS STRUCT, _ '<--- RETURN: Current path
RetVal AS LONG '<--- RETURN: ERR.SUCCESS or
'length of path if Drv$ is
'too small
print Drv$, RetVal
Drv$ = "E:\liberty_basic_pro" + C0$
CALLDLL #DIR, "FN_InitDirPaths", _ '<--- Enumerates the sub-dirs
_ 'of Drv$
Drv$ AS STRUCT, _ '<--- Path to enumerate
RetVal AS LONG '<--- RETURN: The number of paths
'found or ERR.NO.PATHS.FOUND
print RetVal
Drv$ = C0$
CALLDLL #DIR, "FN_GetNextDir", _ '<--- Returns the next consecutive
_ 'one-based path
Drv$ AS STRUCT, _ '<--- RETURN: Sub-dir Path
RetVal AS LONG '<--- RETURN: One-based index of
_ 'path, ERR.NOMORE.ENTRIES or
_ 'required length of Drv$ including
_ 'the null character
PRINT TRIM$(Drv$), RetVal
IF TRIM$(Drv$) = "" THEN
Drv$ = SPACE$(RetVal) + C0$
CALLDLL #DIR, "FN_GetNextDir", Drv$ AS STRUCT, RetVal AS LONG
PRINT TRIM$(Drv$), RetVal
END IF
Mask$ = "*._*, *.txt" + C0$
Drv$ = "E:\liberty_basic_pro\Play_things" + C0$
CALLDLL #DIR, "FN_InitFiles", _ '<--- Enumerates the files in Drv$
_ 'that match Mask$.
_ 'Mask may containg any number of
_ 'comma-deliminated parameters
Drv$ AS STRUCT, _ '<--- Path from which to enumerate
_ 'files
Mask$ AS STRUCT, _ '<--- Type of files to enumerate.
_ 'Mask$ can contain wild-card characters.
_ 'If Mask$ does not contain wild-card characters
_ 'it must be a file name
RetVal AS LONG '<--- RETURN: Number of files enumerated
PRINT RetVal
Drv$ = C0$
CALLDLL #DIR, "FN_GetNextFile", _ '<--- Retrieves the next one-based
_ 'file
Drv$ AS STRUCT, _ '<--- RETURN: File name including path.
RetVal AS LONG '<--- RETURN: One-based index of file or
_ 'ERR.NOMORE.ENTRIES or required length of
_ 'Drv$ including NULL character
PRINT TRIM$(Drv$), RetVal
IF TRIM$(Drv$) = "" THEN
Drv$ = SPACE$(RetVal - 1) + C0$
CALLDLL #DIR, "FN_GetNextFile", Drv$ AS STRUCT, RetVal AS LONG
PRINT TRIM$(Drv$), RetVal
END IF
'/================================================================================/'
' THE FOLLOWING RETURNS INFORMATION
' ABOUT A CURRENTLY EXECUTING FILE
'/================================================================================/'
PARAM = EXE.FULL
CALLDLL #DIR, "FN_GetExecutable", PARAM AS LONG, _ '<--- SEE ENUM ExeType above
Drv$ AS STRUCT, _ '<--- RETURN: File info
RetVal AS LONG '<--- RETURN: ERR.SUCCESS,
'ERR.BUFFER.TO.SMALL,
'ERR.BAD.PARAMETER
PRINT TRIM$(Drv$), RetVal
CLOSE #DIR
WAIT
END
[DONE]
END