copyleft Posted November 12, 2016 Share Posted November 12, 2016 I'm looking to create a script that searches all drives for a particular file, say, "settings.ini" then sets a variable for that file location that I can use to run programs or commands, much like this batch file code: FOR %%d IN (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%d:\Settings.ini SET CFDrv=%%d: del %CFDrv%\*.txt yada, yada, yada... Link to comment Share on other sites More sharing options...
kylomas Posted November 12, 2016 Share Posted November 12, 2016 Is that searching the root folder only? Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
InunoTaishou Posted November 12, 2016 Share Posted November 12, 2016 (edited) expandcollapse popup#include <Array.au3> Global $aDrives = DriveGetDrive("ALL") _ArrayDelete($aDrives, 0) For $i = 0 To UBound($aDrives) - 1 Local $sFoundPath = "" ConsoleWrite("Searching " & $aDrives[$i] & "\ drive for explorer.exe" & @CRLF) If (FileFindFile(StringUpper($aDrives[$i]), "explorer.exe", $sFoundPath)) Then Exit MsgBox("", "", "Found explorer.exe in " & $sFoundPath) Next Func FileFindFile($sStartDir, Const ByRef $vValue, ByRef $sOutString, $iDepth = 0) Local $hSearch = FileFindFirstFile($sStartDir & "\*.*") If (@error) Then Return While (True) Local $hNext = FileFindNextFile($hSearch) If (@error) Then ExitLoop ;If folder, recurse If (StringInStr(FileGetAttrib($sStartDir & "\" & $hNext), "D")) Then FileFindFile($sStartDir & "\" & $hNext, $vValue, $sOutString, $iDepth + 1) Else ; Set the path to the output If ($hNext = $vValue) Then $sOutString = $sStartDir & "\" ExitLoop EndIf EndIf WEnd FileClose($hSearch) Return ($iDepth ? False : True) EndFunc ;==>RecursiveFileSearch Didn't do the same thing a while back but did do something where I was looking for something on a computer and needed to find it (It wasn't explorer.exe lol) Edited November 12, 2016 by InunoTaishou Link to comment Share on other sites More sharing options...
kylomas Posted November 12, 2016 Share Posted November 12, 2016 copyleft, Another alternative (probably much faster)... #include <Array.au3> local $aDrives = DriveGetDrive("ALL") local $sFile = 'sdsf.* mv1.*' local $out For $i = 1 To UBound($aDrives) - 1 ConsoleWrite("Searching " & $aDrives[$i] & ' for ' & $sFile & @CRLF) _srch($aDrives[$i], $sFile) Next $out = stringregexpreplace($out,'(?i)(\w:\\>)|(file not found)','') $out = stringregexpreplace($out, '\R+', @CRLF) ConsoleWrite($out & @CRLF) func _srch($drv, $fle) if DriveStatus($drv) <> 'READY' then return $DOS = Run(@ComSpec & ' /k ' & $drv & ' & cd\ & dir /s /b ' & $sFile, '', '', $STDERR_MERGED) While 1 $out &= StdoutRead($DOS) If @error then exitloop WEnd endfunc kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted November 12, 2016 Share Posted November 12, 2016 And what about _FileListToArrayRec() ? Link to comment Share on other sites More sharing options...
kylomas Posted November 12, 2016 Share Posted November 12, 2016 (edited) Too late here to start testing speeds. Given the breadth of the search I think DIR is faster than any "find first...find next" solution. Besides, started out because I was bored, now just tired. Good Night... Edited November 12, 2016 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
copyleft Posted November 18, 2016 Author Share Posted November 18, 2016 (edited) @kylomas. Very nice script. Many thanks. Is there anyway to constrain the number of drives to speed up the script. In my usage, I know the file is at least not going to be on drives B: or C:. Also, I assume at line 32, I can enter my command based on the drive found? Edited November 18, 2016 by copyleft Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted November 18, 2016 Moderators Share Posted November 18, 2016 Look at DriveGetDrive in the help file, you can modify the "ALL" parameter based on the type of disk, such as all "FIXED" drives. Alternatively, you could simply create your own array of drives to search and pass that parameter to the search function. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
copyleft Posted November 18, 2016 Author Share Posted November 18, 2016 @JLogan3o13. Ok adding the removable drive parameter with DriveGetDrive helps a lot. I'm still confused about where to enter my command, I don't want to output the file name to DOS as kylomas has it. 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