Charly-G Posted April 22, 2006 Share Posted April 22, 2006 Hello, all, i was checking the forum for a routine to find a subfolder where the first occurance of a file-pattern is found. There were a lot of very complex and complicated solutions for that, but i never found a "smart way". So i wrote my own routine to do that and i did it in a smart recursive function. Here is my code: ;A recursive SearchFile-Subroutine ;returns the first path under root $A, where the occurence of file-pattern $B was found $a = "c:" $b = "*.xml" $c=FilePath($a,$ if $c <> "0" then MsgBox(0,"found in path",$c) Else MsgBox(0,"not found","Sorry!") EndIf Exit func FilePath($path,$file) local $s, $pf if fileexists($path) then $attrib=FileGetAttrib($path) if not @error then if StringInStr($attrib, "D") then $s=FileFindFirstFile($path & "\" & $file) FileClose($s) if $s<>-1 then return $path $s=FileFindFirstFile($path & "\*.*") While 1 $f = FileFindNextFile($s) If @error Then ExitLoop if not ($f="." or $f="..") then $pf=$path & "\" & $f $fp=FilePath($pf,$file) if $fp<>"0" then return $fp EndIf WEnd FileClose($s) EndIf endif EndIf EndFunc Link to comment Share on other sites More sharing options...
Charly-G Posted April 22, 2006 Author Share Posted April 22, 2006 Hello, again, found a small bug in my function, when you try to read a folder without permission for that. So here is the correction (change 1 line): wrong line: "while 1" correct line: "while $s<>-1" then everything works fine! Greetings: Charly-G Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now