Trong Posted November 27, 2018 Posted November 27, 2018 (edited) Why ? Source: expandcollapse popup#RequireAdmin #Region #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Change2CUI=y #EndRegion #include <Array.au3> #include <Constants.au3> #include <File.au3> ConsoleWrite("===================================================="&@CRLF) Global $Search_Key = "♡" ;~ Global $Search_Path = @ScriptDir & "\_Source\" Global $Search_Path = "A:\_Webs___\_Source\" Global $Search_FileType = '*.php;*.js;*.xml' Global $iReurn=_SearchInFile($Search_Key, $Search_Path, $Search_FileType) ConsoleWrite($iReurn & " - Error: " & @error & @CRLF) Func _SearchInFile($sSearch, $sFilePath, $sMask = '*', $fRecursive = 1, $fCaseSensitive = True) If (FileExists($sFilePath)<>1) Then Return SetError(-1, 0, 0) Else ConsoleWrite("- File " &$sFilePath&" is Exists !"& @CRLF) EndIf Local $aFileList = _FileListToArrayRec($sFilePath, $sMask, 0, $fRecursive, 1, 2) Local $iError = @error If $iError<>0 Or (IsArray($aFileList)<>1) Then Switch $iError Case 1 ConsoleWrite("! Error: 1 - Path not found or invalid" & @CRLF) Case 2 ConsoleWrite("! Error: 2 - Invalid Include parameter" & @CRLF) Case 3 ConsoleWrite("! Error: 3 - Invalid Exclude parameter" & @CRLF) Case 4 ConsoleWrite("! Error: 4 - Invalid Exclude_Folders parameter" & @CRLF) Case 5 ConsoleWrite("! Error: 5 - Invalid $iReturn parameter" & @CRLF) Case 6 ConsoleWrite("! Error: 6 - Invalid $iRecur parameter" & @CRLF) Case 7 ConsoleWrite("! Error: 7 - Invalid $iSort parameter" & @CRLF) Case 8 ConsoleWrite("! Error: 8 - Invalid $iReturnPath parameter" & @CRLF) Case 9 ConsoleWrite("! Error: 9 - No files/folders found" & @CRLF) EndSwitch Return SetError(1, 0, 0) EndIf For $i = 1 To UBound($aFileList) -1 Local $iFileContent = FileRead($aFileList[$i]) If StringInStr($iFileContent, $sSearch, $fCaseSensitive) Then ConsoleWrite($aFileList[$i] & @CRLF) EndIf Next EndFunc ;==>_SearchInFile ;~ Local $hTimer = TimerInit() ;~ Local $aArray = _FindInFile($SearchKey, $SearchPath, $SearchFileType) ; Search for 'findinfile' within the @ScripDir and only in .au3 & .txt files. ;~ ConsoleWrite(Ceiling(TimerDiff($hTimer) / 1000) & ' second(s)' & @CRLF) ;~ _ArrayDisplay($aArray) ;~ $hTimer = TimerInit() ;~ $aArray = _FindInFile('autoit', @ScriptDir, '*.au3') ; Search for 'autoit' within the @ScripDir and only in .au3 files. ;~ ConsoleWrite(Ceiling(TimerDiff($hTimer) / 1000) & ' second(s)' & @CRLF) ;~ _ArrayDisplay($aArray) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FindInFile ; Description ...: Search for a string within files located in a specific directory. ; Syntax ........: _FindInFile($sSearch, $sFilePath[, $sMask = '*'[, $fRecursive = True[, $fLiteral = Default[, ; $fCaseSensitive = Default[, $fDetail = Default]]]]]) ; Parameters ....: $sSearch - The keyword to search for. ; $sFilePath - The folder location of where to search. ; $sMask - [optional] A list of filetype extensions separated with ';' e.g. '*.au3;*.txt'. Default is all files. ; $fRecursive - [optional] Search within subfolders. Default is True. ; $fLiteral - [optional] Use the string as a literal search string. Default is False. ; $fCaseSensitive - [optional] Use Search is case-sensitive searching. Default is False. ; $fDetail - [optional] Show filenames only. Default is False. ; Return values .: Success - Returns a one-dimensional and is made up as follows: ; $aArray[0] = Number of rows ; $aArray[1] = 1st file ; $aArray[n] = nth file ; Failure - Returns an empty array and sets @error to non-zero ; Author ........: guinness ; Remarks .......: For more details: http://ss64.com/nt/findstr.html ; Example .......: Yes ; =============================================================================================================================== Func _FindInFile($sSearch, $sFilePath, $sMask = '*', $fRecursive = True, $fLiteral = Default, $fCaseSensitive = Default, $fDetail = Default) Local $sCaseSensitive = $fCaseSensitive ? '' : '/i', $sDetail = $fDetail ? '/n' : '/m', $sRecursive = ($fRecursive Or $fRecursive = Default) ? '/s' : '' If $fLiteral Then $sSearch = ' /c:' & $sSearch EndIf If $sMask = Default Then $sMask = '*' EndIf $sFilePath = StringRegExpReplace($sFilePath, '[\\/]+$', '') & '\' Local Const $aMask = StringSplit($sMask, ';') Local $iPID = 0, $sOutput = '', $sCMD = '' For $i = 1 To $aMask[0] $sCMD = 'findstr ' & $sCaseSensitive & ' ' & $sDetail & ' ' & $sRecursive & ' "' & $sSearch & '" "' & $sFilePath & $aMask[$i] & '"' ConsoleWrite("cmd: " & $sCMD & @CRLF) ;~ MsgBox(0,"",$sCMD) $iPID = Run(@ComSpec & ' /c ' & $sCMD, @SystemDir, @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($iPID) $sOutput &= StdoutRead($iPID) Next Return StringSplit(StringStripWS(StringStripCR($sOutput), BitOR($STR_STRIPLEADING, $STR_STRIPTRAILING)), @LF) EndFunc ;==>_FindInFile Edited November 27, 2018 by VIP Regards,
FrancescoDiMuro Posted November 27, 2018 Posted November 27, 2018 @VIP I think you missed the "\" between the file path and the filter Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
FrancescoDiMuro Posted November 27, 2018 Posted November 27, 2018 (edited) @VIP Pay attention In _FileListToArrayRec() you are using $Search_Path = "A:\_Webs___\_Source\", and $sMask = "*", which makes the function to search for _FileListToArrayRec("A:\_Webs___\_Source\", "*") which causes the error 1 to appear Edited November 27, 2018 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Trong Posted November 27, 2018 Author Posted November 27, 2018 Thanks for support ! I have found the problem with 'True <> 1' and ' False <> 0' $iRecur need is 1 or 0 to work ! Quote $iRecur[optional] Specifies whether to search recursively in subfolders and to what level $FLTAR_NORECUR (0) - Do not search in subfolders (Default) $FLTAR_RECUR (1) - Search in all subfolders (unlimited recursion) Negative integer - Search in subfolders to specified depth Regards,
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