' ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ' º Uploaded by: º² ' º Scott Tucker º² ' º Creative Software Alliance º² ' º 16 Lakeville Hwy. º² ' º Petaluma, CA 94952 º² ' º (707)778-1591 º² ' º º² ' º On: 07/09/1994 º² ' º º² ' º You, of course, may use this code in any manner º² ' º you see fit. If it kills your computer or does º² ' º any damage at all, I am not to blame. Sorry about º² ' º the caveat. º² ' º º² ' º Many of the ideas for this Procedure were taken º² ' º from "BASIC Techniques and Utilities" by Ethan º² ' º Winer, and Peter Norton's "Programmers Guide to º² ' º the PC". º² ' º º² ' º º² ' ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ² ' ²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²² Cls ReDim F$(0) ' create a dynamic array to hold file names ' <<< Call the procedure >>> ' Call GetFiles("*.*", 1, 0, F$()) ' all files only Call GetFiles("*.exe", 1, -1, F$()) ' all .exe files only, sorted ' Call GetFiles("*.*", 2, 0, F$()) ' directories only ' Call GetFiles("*.*", 3, 0, F$()) ' all files and directories ' Call GetFiles("*.bas", 1, 0, F$()) ' *.bas files only. ' Call GetFiles("*.bas", 4, 0, F$()) ' *.bas files that need backing up C% = UBound(F$) ' How many did we get? Print "You got";C%;"files back." For K%=1 to C% ' Show 'em to me Print F$(K%), next End '=========== ' ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ' ÌÍ͹ This is the Procedure. ÌÍ͹ ' ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ Sub GetFiles(ByVal FileSpec$, ByVal FileType%, ByVal SortList%, _ FileNameArray$()) ' FileSpec$ = name of file or wildcard convention, Full Path support. ' FileType% 1 = Regular files ' 2 = Subdirectories ' 3 = All files and directories ' 4 = Only files with archive bit set ' SortList% Boolean True = sort array; False = no sort ' FileNameArray$() must be Dim'ed as a Dynamic array before ' being passed into this proc. It will be ReDim'ed to hold ' the exact number of files to be returned. ' Assumes no more than 1000 files will be returned. ' To get subdir names, pass the "*.*" filespec with ' a type 2 file type. '================================================= Local Maxfiles%, Temp$(), Count%, FSpec$, K%, Nam$, Att$ MaxFiles% = 1000 ' increase if necessary. ReDim Temp$(1 to MaxFiles%) ' temp file holder If FileSpec$ = "" then Exit Sub ' why bother? If FileType% < 1 or FileType% > 4 then FileType% = 1 ' just in case MYDTA$ = Space$(44) ' create a DTA area REG 8, StrSeg(MYDTA$) REG 4, StrPtr(MYDTA$) REG 1, &H1A00 ' set DTA area Call Interrupt(&H21) FSpec$ = FileSpec$ + Chr$(0) ' create an ascii z string Count% = 0 ' initialize counter REG 8, StrSeg(FSpec$) ' define the files to look at REG 4, StrPtr(FSpec$) REG 3, 63 ' first look at all files REG 1, &H4E00 ' get first file DO Call Interrupt(&H21) If REG(1) = 18 then Exit DO ' no more files 'Dum$ = Left$(MYDTA$,21) ' DOS reserved area. 'Tim$ = Mid$(MYDTA$,23,2) ' file time, must be formatted 'Dat$ = Mid$(MYDTA$,25,2) ' file date, must be formatted 'Siz& = Val(Mid$(MYDTA$,27,4)) ' file size Att$ = Mid$(MYDTA$,22,1) ' file attribute Nam$ = Mid$(MYDTA$, 31, 13) ' file name Nam$ = Left$(Nam$, Instr(Nam$, Chr$(0))-1) Select Case FileType% Case 1 ' files only If (ASC(Att$) and 16) < 16 then ' a file? Incr Count% Temp$(Count%) = Nam$ End If Case 2 ' directories only If (ASC(Att$) and 16) = 16 then ' a directory? If Left$(Nam$, 1) <> "." then ' ignore "." and ".." Incr Count% Temp$(Count%) = Nam$ End If End If Case 3 ' all files and directories If (ASC(Att$) and 16) then ' a directory? If Left$(Nam$, 1) <> "." then ' ignore "." and ".." Incr Count% Temp$(Count%) = Nam$ End If Else ' its a regular file Incr Count% Temp$(Count%) = Nam$ End If Case 4 ' all files with archive bit set If (ASC(Att$) and 32) then ' archive bit set Incr Count% Temp$(Count%) = Nam$ End If Case Else End Select REG 1, &H4F00 ' find next LOOP Until Count% = MaxFiles% If Count% > 0 then ' fill the return array ReDim FileNameArray$(1:Count%) For K%=1 to Count% FileNameArray$(K%) = Temp$(K%) Next If SortList% then Array Sort FileNameArray$() ' sort, if required End If Erase Temp$ ' kill temp array End Sub ' ÉÍÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÍ» ' ÈÍÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏͼ