BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"Recursive directory search"
, by thechange
Search by extension with sub-directories.
Code
; Demonstrating searching for files by extension. ; Includes sub-directories e.g. recursive function calls. ; ; Don't be alarmed when you *think* nothing is happening. ; It takes a while to scan drives usually :) ;<-- Usage Graphics 400 , 1000 , 0 , 2 ScanDir "C:" , ".WAV;.MP3;.IT;.S3M;.WMA" ; Search for audio Print "--------------------------------------------------------------------------------" SetFont LoadFont ( "Arial" , 1 ) ; Tiny font (unreadable) For Found.Match = Each Match ; Dump list of what was found Print Found\FileName Next WaitKey End ;<-- Internal Type Match Field FileName$ End Type Type Format Field Extension$ End Type Function ScanDir ( Dir$ , TypeSpec$ ) ;Print Dir ; Uncomment to see the directories being scanned If Right ( Dir , 1 ) = "\" ; Dirspec trailing backslash Dir = Left ( Dir , Len ( Dir ) - 1 ) End If ;- Separate extensions If TypeSpec <> "" Delete Each Format Delete Each Match Local Spec.Format Local Extension$ Local Counter = 0 Repeat Counter = Counter + 1 Extension = GetTok ( TypeSpec , Counter , ";" ) If Extension <> "" Spec = New Format Spec\Extension = Upper ( Extension ) End If Until Extension = "" End If ;- Directory scan Local DirHandle = ReadDir ( Dir ) Local Found.Match Local FileName$ Repeat FileName = NextFile ( DirHandle ) If FileName <> "" If FileName <> "." If FileName <> ".." If FileType ( Dir + "\" + FileName ) = 2 ; It's a directory! ScanDir Dir + "\" + FileName , "" ; Go down one level Else ; It's a file! ;- Check for matching extension For Spec = Each Format If Upper ( Right ( FileName , Len ( Spec\Extension ) ) ) = Spec\Extension Found = New Match Found\FileName = Dir + "\" + FileName Exit End If Next End If End If End If Until FileName = "" ; No more files End Function ; Parameter parser Function gettok$(from$,which,space$=" ") ; Created by skn3[ac] Local foundword=False Local mode=False Local current=0 Local maketok$="" Local getchar$="" For i=1 To Len(from$) getchar$=Mid$(from$,i,1) If foundword=False Then If mode=False Then If getchar$<>space$ Then mode=True current=current+1 End If If current=which Then foundword=True maketok$=maketok$+getchar$ End If Else If getchar$=space$ Then mode=False End If End If Else If getchar$=space$ Then Exit Else maketok$=maketok$+getchar$ End If End If Next Return maketok$ End Function ;-->
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations