AZJIO Posted October 3, 2012 Author Share Posted October 3, 2012 (edited) Trying to make a function to filter by attributesexpandcollapse popup#include <Array.au3> ; для _ArrayDisplay #include <FileOperations.au3> $FileList = _FO_FileSearch(@SystemDir & 'drivers', '*.sys') $cn = $FileList[0] $Filters = 'RHS' $timer = TimerInit() ; _AttribFilters($FileList, $Filters, 0, 1) _AttribFilters($FileList, $Filters, 0, 0) $timer = Round(TimerDiff($timer) / 1000, 2) & ' sec' ; _ArrayDisplay($FileList, $timer & ', ' & $cn) MsgBox(0, 'FileList, ' & $cn & ', ' & $Filters & ', ' & $timer, $FileList) Func _AttribFilters(ByRef $aFileList, $sAttrib, $iExclude = 1, $iArray = 1) $sAttrib = StringRegExpReplace(StringUpper($sAttrib), '[^RASHNOT]', '') If Not $sAttrib Then Return SetError(2, 0, '') If $iExclude Then $sAttrib = '^' & $sAttrib If $iArray Then $c = 0 For $i = 1 To $aFileList[0] $sFileAttrib = FileGetAttrib($aFileList[$i]) If StringRegExp($sFileAttrib, '[' & $sAttrib & ']') Then $c += 1 $aFileList[$c] = $aFileList[$i] EndIf Next If $c Then $aFileList[0] = $c ReDim $aFileList[$c + 1] Else Dim $aFileList[1] = [0] Return SetError(3, 0, '') EndIf Else $c = '' For $i = 1 To $aFileList[0] $sFileAttrib = FileGetAttrib($aFileList[$i]) If StringRegExp($sFileAttrib, '[' & $sAttrib & ']') Then $c &= $aFileList[$i] & @CRLF EndIf Next $c = StringTrimRight($c, 2) If $c Then $aFileList = $c Else Return SetError(3, 0, '') EndIf EndIf EndFuncSpeed testif Len($sAttrib)>4 Then Time(SPE) < Time(StringInStr)expandcollapse popupGlobal $aFileAttrib[8] = [7, _ 'RASH', _ 'R', _ 'A', _ 'SH', _ 'RSH', _ 'ASH', _ 'RASHNOT'] $sAttrib = 'RSHT' $timer = TimerInit() $c1 = _AttribFilters($aFileAttrib, $sAttrib) $d1 = @extended $t1 = Round(TimerDiff($timer), 2) & ' msec' $timer = TimerInit() $c2 = _AttribFilters1($aFileAttrib, $sAttrib) $d2 = @extended $t2 = Round(TimerDiff($timer), 2) & ' msec' MsgBox(0, '', _ 'StrStr:' & @Tab & $c1 & @Tab & $d1 & @Tab & $t1 & @CRLF & _ 'SPE..:' & @Tab & $c2 & @Tab & $d2 & @Tab & $t2) Func _AttribFilters($aFileAttrib, $sAttrib) Local $c = 0, $d = 0 $asAttrib = StringSplit($sAttrib, '') If @error Then Return For $s = 1 To 1000 For $i = 1 To $aFileAttrib[0] For $j = 1 To $asAttrib[0] If StringInStr($aFileAttrib[$i], $asAttrib[$j]) Then $d += 1 ContinueLoop 2 EndIf Next $c += 1 Next Next Return SetError(0, $d, $c) EndFunc Func _AttribFilters1($aFileAttrib, $sAttrib) Local $c = 0, $d = 0 For $s = 1 To 1000 For $i = 1 To $aFileAttrib[0] If StringRegExp($aFileAttrib[$i], '[' & $sAttrib & ']') Then $d += 1 Else $c += 1 EndIf Next Next Return SetError(0, $d, $c) EndFunc Edited January 23, 2013 by AZJIO My other projects or all Link to comment Share on other sites More sharing options...
legend Posted October 27, 2012 Share Posted October 27, 2012 (edited) how do a search for a specefic file, and return the result, if it is found Edited October 27, 2012 by legend Link to comment Share on other sites More sharing options...
AZJIO Posted October 27, 2012 Author Share Posted October 27, 2012 (edited) how do a search for a specefic file, and return the result, if it is found #include <Array.au3> ; _ArrayDisplay #include <FileOperations.au3> ; Example 1 $aFileList = _FO_FileSearch('C:WINDOWSsystem', 'specific_file.tmp') If Not @error Then _ArrayDisplay($aFileList) ; Example 2 $aFileList = _FO_FileSearch(@WindowsDir, 'shell32.dll') If Not @error Then _ArrayDisplay($aFileList) ; Example 3 $sFileList = _FO_FileSearch(@WindowsDir, 'shell32.dll', True, 125, 1, 0) If Not @error Then MsgBox(0, 'Yes?', $sFileList) Edited January 23, 2013 by AZJIO My other projects or all Link to comment Share on other sites More sharing options...
legend Posted October 28, 2012 Share Posted October 28, 2012 Hi AZJIO thanks alot.But i noticed when searching, it gives this tray tip: Link to comment Share on other sites More sharing options...
AZJIO Posted October 28, 2012 Author Share Posted October 28, 2012 This is not a problem of the UDF, is the problem of your files. FileFindFirstFile, FileFindNextFile Is Used. The system accesses the broken files. You can read about it in Google. My other projects or all Link to comment Share on other sites More sharing options...
legend Posted October 28, 2012 Share Posted October 28, 2012 ok thanks, I enjoy using you UDF alot Link to comment Share on other sites More sharing options...
AZJIO Posted October 29, 2012 Author Share Posted October 29, 2012 Added CHM file in the archive and online page. My other projects or all Link to comment Share on other sites More sharing options...
legend Posted November 8, 2012 Share Posted November 8, 2012 (edited) the code you wrote in #21 Is there a way to exclude a folder, so it doesn't search in a specified folder? I want to search the content for diffrent drives for .txt files, ex d: but exclude a folder on d:\ Edited November 8, 2012 by legend Link to comment Share on other sites More sharing options...
AZJIO Posted November 9, 2012 Author Share Posted November 9, 2012 Need to get a list of folders, and then do a search for each folder, except the specified. The folder you exclude can be in other directories. This will give the wrong result. So I did not add in the option to exclude folders. A little later I'll do an example, but not for the UDF. My other projects or all Link to comment Share on other sites More sharing options...
AZJIO Posted November 10, 2012 Author Share Posted November 10, 2012 (edited) expandcollapse popup#include <Array.au3> ; _ArrayDisplay #include <FileOperations.au3> $FileList = _FO_FileSearchExceptions(@HomeDrive, '*exe', True, '*Settings|MSOCache|Program Files|RECYCLER|System Volume Information|WINDOWS', 125, 1, 0) MsgBox(0, @error, $FileList) ; $FileList = _FO_FileSearchExceptions(@HomeDrive, '*exe', True, '*Settings|MSOCache|Program Files|RECYCLER|System Volume Information|WINDOWS') ; _ArrayDisplay($FileList) Func _FO_FileSearchExceptions($sPath, $sMask = '*', $fInclude = True, $sExceptions = '', $iDepth = 125, $iFull = 1, $iArray = 1, $iTypeMask = 1, $sLocale = 0) Local $vFolderList If Not $sExceptions Then $vFolderList = _FO_FileSearch($sPath, $sMask, $fInclude, $iDepth, $iFull, $iArray, $iTypeMask, $sLocale) Return SetError(@error, 0, $vFolderList) EndIf Local $i, $rgex, $vFileList = '' $vFolderList = _FO_FolderSearch($sPath, '*', True, 0, 0, 0) If @error Then $vFolderList = _FO_FileSearch($sPath, $sMask, $fInclude, $iDepth, $iFull, $iArray, $iTypeMask, $sLocale) Return SetError(@error, 0, $vFolderList) EndIf $sExceptions = StringReplace(StringReplace(StringRegExpReplace($sExceptions, '[][$^.{}()+]', '$0'), '?', '.'), '*', '.*?') If Not $sLocale Then $rgex = 'i' ElseIf Not ($sLocale == '1') Then $rgex = 'i' $sExceptions = __FO_UserLocale($sExceptions, $sLocale) EndIf $vFolderList = StringTrimRight(StringRegExpReplace($vFolderList & @CRLF, '(?m' & $rgex & ')^(' & $sExceptions & ')rn', ''), 2) If Not $vFolderList Then $vFolderList = _FO_FileSearch($sPath, $sMask, $fInclude, $iDepth, $iFull, $iArray, $iTypeMask, $sLocale) Return SetError(@error, 0, $vFolderList) EndIf ; MsgBox(0, '???', '|' & $vFolderList & '|') $vFolderList = StringSplit($vFolderList, @CRLF, 1) ; _ArrayDisplay($vFolderList) For $i = 1 To $vFolderList[0] $vFileList &= _FO_FileSearch($sPath & '' & $vFolderList[$i], $sMask, $fInclude, $iDepth, 1, 0, $iTypeMask, $sLocale) If Not @error Then $vFileList &= @CRLF Next $vFileList &= _FO_FileSearch($sPath, $sMask, $fInclude, 0, 1, 0, $iTypeMask, $sLocale) ; ??? If @error Then $vFileList = StringTrimRight($vFileList, 2) ; $vFileList = StringTrimRight($vFileList, 2) If Not $vFileList Then Return SetError(3, 0, '') Switch $iFull Case 0 $vFileList = StringRegExpReplace($vFileList, '(?m)^(?:.{' & StringLen($sPath) & '})(.*)$', '1') Case 2 $vFileList = StringRegExpReplace($vFileList, '(?m)^(?:.*)(.*)$', '1') Case 3 $vFileList = StringRegExpReplace($vFileList, '(?m)^(?:.*)([^]*?)(?:.[^.]+)?$', '1' & @CR) $vFileList = StringTrimRight($vFileList, 1) EndSwitch Switch $iArray Case 1 $vFileList = StringSplit($vFileList, @CRLF, 1) Case 2 $vFileList = StringSplit($vFileList, @CRLF, 3) EndSwitch Return $vFileList EndFunc ;==>_FO_FileSearchExceptions Edited January 23, 2013 by AZJIO My other projects or all Link to comment Share on other sites More sharing options...
AZJIO Posted April 27, 2013 Author Share Posted April 27, 2013 (edited) Update, v1.6.2, 28.04.2013 $sPath = "" now it causes a mistake _FO_SearchEmptyFolders: I used _FO_IsDir instead of FileExists Edited April 27, 2013 by AZJIO My other projects or all Link to comment Share on other sites More sharing options...
AZJIO Posted May 25, 2013 Author Share Posted May 25, 2013 I added the option $vExcludeFolders $$vExcludeFolders - Excludes folders from search, only the root. List the folder names via the "|", for example, "Name1|Name2|Name3|". FileOperations.7z The main file is not updated, but I think I will leave this option. The search speed is not reduced and the exclusion of unnecessary search faster. My other projects or all Link to comment Share on other sites More sharing options...
AZJIO Posted May 29, 2013 Author Share Posted May 29, 2013 How it is more convenient to pass a list of exceptions? As a single parameter or as a component? $sPath = 'C:\Program Files\<Program Files|WINDOWS>' _FO_FileSearch_Test($sPath) Func _FO_FileSearch_Test($sPath) If StringRight($sPath, 1) = '>' Then $iPos = StringInStr($sPath, '<', 1, -1) $vExcludeFolders = StringTrimRight(StringTrimLeft($sPath, $iPos), 1) $sPath = StringLeft($sPath, $iPos - 1) EndIf MsgBox(0, 'Сообщение', $sPath & @LF & $vExcludeFolders) EndFunc My other projects or all Link to comment Share on other sites More sharing options...
AZJIO Posted June 15, 2013 Author Share Posted June 15, 2013 Update, v1.7, 2013.06.15 My other projects or all Link to comment Share on other sites More sharing options...
AZJIO Posted July 17, 2013 Author Share Posted July 17, 2013 (edited) To me reported about a mistake in version 1.7. When testing the 1.6 version works fine. At version 1.7, an error (Win7 x64) previously called with Const or expression on ByRef param C:Program Files (x86)AutoIt3IncludeFileOperations.au3(238,155) : ERROR: __FO_FileSearchType() previously called with Const or expression on ByRef param(s). Func __FO_FileSearchType(ByRef $sFileList, $sPath, ByRef $sMask, ByRef $fInclude, ByRef $iDepth, ByRef $aExcludeFolders, ByRef $iExcludeDepth, $iCurD = 0) C:\Program Files (x86)\AutoIt3\Include\FileOperations.au3(147,118) : REF: first call to __FO_FileSearchType(). __FO_FileSearchType($vFileList, $sPath, '|' & $sMask & '|', $fInclude, $iDepth, $vExcludeFolders, $iExcludeDepth) #include <Array.au3> ; for _ArrayDisplay #include <FileOperations.au3> $timer = TimerInit() $FileList = _FO_FileSearch(@WindowsDir, 'exe|dll|txt|zip', True, 2, 0, 1, 2, 0, 'system32', 0) $timer = Round(TimerDiff($timer) / 1000, 2) & ' sec' _ArrayDisplay($FileList, 'timer ' & $timer) I checked on Win7 x64, Win8 x64, there were no errors. I used to save memory ByRef. So that when the depth of recursion 20 used one copy. Has anyone any thoughts on this? Edited: Apparently gives Au3Check.exe error when run from Scite.exe Edited July 17, 2013 by AZJIO My other projects or all Link to comment Share on other sites More sharing options...
wraithdu Posted July 17, 2013 Share Posted July 17, 2013 (edited) This error should go away in the new betas and stable release. I'm not sure if this is just an Au3Check error, but I don't think so. The issue is you can only use a non Const variable as an argument to a ByRef function parameter. In your example, you're passing a string - '|' & $sMask & '|' - which is not allowed. You could work around it by setting the value of $sMask = '|' & $sMask & '|' before calling the function, and passing just $sMask. Edited July 17, 2013 by wraithdu Link to comment Share on other sites More sharing options...
AZJIO Posted July 17, 2013 Author Share Posted July 17, 2013 (edited) string - '|' & $sMask & '|' - which is not allowed. Func __FO_FileSearchType(ByRef $sFileList, $sPath, ByRef $sMask, ByRef $fInclude, ByRef $iDepth, ByRef $aExcludeFolders, ByRef $iExcludeDepth, $iCurD = 0) In the previous message it was not mine I disabled the enforced validation AutoIt3Wrapper.ini [Other] Run_AU3Check=n Edited July 17, 2013 by AZJIO My other projects or all Link to comment Share on other sites More sharing options...
AZJIO Posted May 14, 2014 Author Share Posted May 14, 2014 Reported a new problem: If a symbolic link to a directory is in the same directory, then it leads to an infinite loop. c:ProgramData -> Application Data -> c:ProgramData ...etc GetFileAttributes? FILE_ATTRIBUTE_REPARSE_POINT? My other projects or all Link to comment Share on other sites More sharing options...
AZJIO Posted May 24, 2014 Author Share Posted May 24, 2014 Update v1.8.4+ _FO_CreateFile My other projects or all Link to comment Share on other sites More sharing options...
legend Posted August 8, 2015 Share Posted August 8, 2015 (edited) nvm Edited August 10, 2015 by legend 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