Roman Posted May 15, 2008 Share Posted May 15, 2008 Hi I need a simple code snippet (function) that searches for a specific file in a given directory and ALL its subdirectories. The filename i search for is given - i need no wildcards. The function should return the path to this file or the files (if more than one is found). I have browsed through help und example files in this forum but nothing found. Is there a crack who can help me? Thanks, Roman. Link to comment Share on other sites More sharing options...
Zedna Posted May 15, 2008 Share Posted May 15, 2008 Search on the forum for: _FileSearch() _FileListToArrayEx() Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
ChrisL Posted May 15, 2008 Share Posted May 15, 2008 (edited) You can modify this to do what you need Search ("C:\Windows","hal.dll");replace with your search directory and file required Func Search($current,$toFind) If StringRight($current,1) = "\" then $current = StringTrimRight($current,1) Local $search = FileFindFirstFile($current & "\*.*") While 1 Dim $file = FileFindNextFile($search) If @error Or StringLen($file) < 1 Then ExitLoop If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then IF $file = $toFind then Msgbox(0,"File found", $current & "\" & $file); you could add it to an array or whatever else you wanted to do with it EndIf If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then Search($current & "\" & $file, $toFind) EndIf WEnd FileClose($search) EndFunc Edited May 15, 2008 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
doorito Posted August 20, 2008 Share Posted August 20, 2008 You can modify this to do what you need Search ("C:\Windows","hal.dll");replace with your search directory and file required Func Search($current,$toFind) If StringRight($current,1) = "\" then $current = StringTrimRight($current,1) Local $search = FileFindFirstFile($current & "\*.*") While 1 Dim $file = FileFindNextFile($search) If @error Or StringLen($file) < 1 Then ExitLoop If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then IF $file = $toFind then Msgbox(0,"File found", $current & "\" & $file); you could add it to an array or whatever else you wanted to do with it EndIf If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then Search($current & "\" & $file, $toFind) EndIf WEnd FileClose($search) EndFunc Your code worked perfectly...Thank you, it's exactly what I needed . 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