News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

GetAllFilesInDir

Started by kevin, July 25, 2006, 10:29:56 PM

Previous topic - Next topic

kevin

 Get All Files In Dir / Folder

 This PlayBASIC function fills an array with all the files found within the folder.



PlayBASIC Code: [Select]
 path$=currentdir$()


Dim Files$(1)
FilesFound=GetAllFilesInDir(Files$(),path$)

Print FilesFound
For lp=0 to FilesFound-1
f$=files$(lp)
if len(f$)>50 then f$="..."+right$(f$,50)
print f$
Next

Sync
waitkey







Function GetAllFilesInDir(File$(),path$)
oldpath$=currentdir$()
Dim TempScanfolder$(500)
do
FilesFound,FoldersFound=Priv_Scanfolder(file$(),TempScanfolder$(),FilesFound,FoldersFound,path$)
if FOldersFound>0
dec FoldersFound
path$=TempScanfolder$(FoldersFound)+"\"
else
exitdo
endif
loop
undim TempScanfolder$()
redim Files$(FilesFound)
cd oldpath$
Endfunction FilesFound



` *=----------------------------------------------------------------=*
` The following functions are just used in the process
` *=----------------------------------------------------------------=*

Function Priv_Scanfolder(file$(),Folder$(),FilesFound,FoldersFound,path$)
FileArraySize =GetArrayElements(Files$(),1)
FolderArraySize =GetArrayElements(Files$(),1)

CD path$

File$=FirstFile$(path$)
While File$<>""
if _FileLib_Screen_Filename(file$)
Filename$=Path$+File$
if FileType(filename$)=1
; Add the File
if FilesFound=>FileArraySize
NewSize=FilesFound * 2
if NewSize<250 then NewSize=250
ReDim Files$(NewSize)
FileArraySize=getarrayelements(Files$(),1)
endif
Files$(FilesFound)=Filename$
inc FilesFound
else
; Ad folder
if FoldersFound=>FolderArraySize
NewSize=FoldersFound * 2
if NewSize<1000 then NewSize=1000
Redim Folder$(NewSize)
FolderArraySize=getarrayelements(Folder$(),1)
endif
Folder$(FoldersFound)=Filename$
inc FoldersFound
endif
endif
File$=NextFile$()
EndWhile
EndFunction FilesFound,FoldersFound


Function _FileLib_Screen_Filename(filename$)
select filename$
case ".", ".." , "\"
exitfunction false
default
exitfunction true
endselect
endFunction flag






 Related To:

   Get All Files In Folder (Sorted)

   PlayBASIC Documentation - FILE COMMANDS