AZJIO

_FileSearch + _FolderSearch

41 posts in this topic




Excellent !

5.64 sec for 313572 files !

It takes more time to display array than searching files...

Thanks to share ! :graduated:


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi guys! This is amazing function and it work fine with files. Problem is that I couldn't make it to work with folders...

#include <File.au3>
#include <Array.au3> ; i dont need this but i also did try with arrays
#include <_FileSearch.au3>
#include <string.au3>
 
 
; $file contain list of folders separated by @CR which I would like to find and copy to desired place
; filenames inside contain symbols like "-" "_" "(" ")" but that shouldnt be a problem
$file="search.txt"
; set counter on 1st line in search.txt
$cnt01=1
; $destination where i want all files to be copied to
$destination="f:\S\@@\"
; $countlines
$countlines=_FileCountLines("search.txt")
 
 
Do
; $fol is the name of first folder from the list (search.txt) that i want to find and copy to $destination
$fol=FileReadLine($file,$cnt01)
; $relpath should contain full path to first folder that has been found
; 15 is search depth, 1 means i want full path to a folder and 0 means it wont be an array
$folpath=_FolderSearch('f:\M\',$fol,15,1,0)
; copy folder and its contents to a $destination ,1 and overwrite files if there are any
DirCopy($folpath, $destination, 1)
; increase counter to read next line in search.txt
$cnt01 = $cnt01 + 1
; work like that until last line in file
Until $cnt01 > $countlines
; do a beep beep when everything is done
Beep(1000,100)
Exit

I did try and put MsgBox with variables to see what happens but couldnt make it to find first folder i would like to be found

It gets first folder name well but I couldnt get the hit from function:

$relpath=_FolderSearch('f:\M\',$fol,15,1,0)

Contents of a search.txt would be something like this:

Pictures_Not-Vacation_Sea-(2001)-Me

Video_And_Sounds-Vacation_Sea-(2001)-Me

etc.

Edited by Fr33b0w

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Fr33b0w

; $Include = True (parameters can not be ignored)
; 1 - result in an ARRAY where $array[0]=number of folders (BY DEFAULT)
$folpath=_FolderSearch('f:\M\',$fol, True,15)
If Not @error Then
For $i = 1 to $folpath[0]
  DirCopy($folpath[$i], $destination, 1)
Next
EndIf

the script works well, tested

#include <File.au3>
#include <_FileSearch.au3>
$file="search.txt"
$cnt01=1
$destination="F:\S\@@\"
$countlines=_FileCountLines("search.txt")
While $cnt01 <= $countlines
$fol=FileReadLine($file,$cnt01)
; $Include = True (parameters can not be ignored)
; 1 - result in an ARRAY where $array[0]=number of folders (BY DEFAULT)
$folpath=_FolderSearch('F:\M\',$fol, True,15)
If Not @error Then
For $i = 1 to $folpath[0]
  DirCopy($folpath[$i], $destination&'\'&$fol, 1)
Next
EndIf
$cnt01 += 1
WEnd
Beep(1000,100)
Edited by AZJIO

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

1. Try _FileSearch_example

2. Try $fol = '*'

3. Check the error after the function _FolderSearch

$folpath=_FolderSearch('F:\M\',$fol, True,15)
MsgBox(0, 'Message', @error)

4. Check that the folder names are in the file search.txt

5. Check the simplified method

$folpath=_FolderSearch('F:\M\', 'Pictures_Not-Vacation_Sea-(2001)-Me', True,15)
MsgBox(0, 'Message', @error)
Edited by AZJIO
1 person likes this

Share this post


Link to post
Share on other sites

I am so sorry. I was lost my head while I had problem with script before You helped me first time and since I was trying everything to make it work I forgot to switch back hdd letter. So I wasted Your time even more then it was needed (mine time also). Script works in background and it works perfect. This what You made is very useful tool, at least it is for me so I thank You very much for that (spasibo)! Again, thank You for Your time. I wouldnt make it if You didnt helped me!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I have been using _filesearch for a few months but I have recently ran into a problem. Currently I can only get it to work over the network if I map a drive to the other machine. Has anyone else been able to use the IP to do searches? I.E. 192.168.0.10folder Every time I try it returns no results. Another question I have is it states in the comments "If an empty folder, it returns an empty string or array with one element $array[0]=0". Now I have very limited experience with Autoit but I have taken classes in C and C++. Can you have an array with only one element in autoit? The reason why I ask is from my testing it seems that it is not returning an array when no files are found, just a variable with value "0" in it. Thank you for this function and any help you can offer.

Edited by pbc0011

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Function is updated, and now if the folder is empty or nothing is found, it returns an @error=3

192.168.0.10folder

Remove the line in the function _FileSearch and _FolderSearch

If Not StringRegExp($Path, '(?i)^[a-z]:[^/:*?"<>|]*$') Or StringInStr($Path, '') Then Return SetError(1, 0, '')

I tried to use a regular expression to validate the path. But I do not understand what paths are used for network drives to make a regular expression. Maybe it does not even need to check.

Edited by AZJIO

Share this post


Link to post
Share on other sites

Azjio,

Thanks for the quick response and making the adjustments. I'm having a little trouble understanding what exactly the @error macro does but Ill have to dig a little deeper into the help file. I really do need the ability to search over the network so I'm going to try and do a little research on that too.

Share this post


Link to post
Share on other sites

pbc0011

$FileList=_FileSearch($Path)
Switch @error
Case 1
  MsgBox(0, 'Error', 'Invalid path')
Case 2
  MsgBox(0, 'Error', 'Invalid mask')
Case 3
  MsgBox(0, 'Error', 'not found')
Case Else
  MsgBox(0, 'no errors', 'found')
EndSwitch
$FileList=_FileSearch($Path)
If Not @error Then
; activity
EndIf
$FileList=_FileSearch($Path)
If @error Then Exit

Share this post


Link to post
Share on other sites

Ahh thank you

Share this post


Link to post
Share on other sites

When the correction masks are allowed whitespace characters and point at the beginning of the file name.

Fixed three bugs are not critical.

Added check for existence of the path, instead of validation.

Share this post


Link to post
Share on other sites

_PathSearch

#include <Array.au3> ; для _ArrayDisplay
#include <_FileSearch.au3>
$FileList=_PathSearch('C:WINDOWSsystem', '*ystemm*|*ystem*z*|*ystemo*', True, 125)
; $FileList=_GetListMask('C:WINDOWSsystem', '*ystemM*', False, 125)
MsgBox(0, 'Сообщение', $FileList)
$FileList = StringSplit($FileList, @CRLF, 1)
_ArrayDisplay($FileList, UBound($FileList)&' - RegExp')
; Получение списка и обработка регулярным выражением
Func _PathSearch($Path, $Mask, $Include, $Depth)
Local $aFileList, $FileList
$FileList=_FileSearch($Path, '*', True, $Depth, 1, 0)
$Mask = StringReplace(StringReplace(StringRegExpReplace($Mask, '[][$^.{}()+]', '$0'), '?', '.'), '*', '.*?')
If $Include Then
  $aFileList = StringRegExp($FileList, '(?mi)^(' & $Mask & ')(?:r|z)', 3)
  $FileList = ''
  For $i = 0 To UBound($aFileList) - 1
   $FileList &= $aFileList[$i] & @CRLF
  Next
Else
  $FileList = StringRegExpReplace($FileList & @CRLF, '(?mi)^(' & $Mask & ')rn', '')
EndIf
$FileList = StringReplace(StringTrimRight($FileList, 2), '|', '')
Return $FileList
EndFunc

Share this post


Link to post
Share on other sites

Thanks for the PathSearch option

Ive just been playing with it to try and understand it with this

$FileList=_PathSearch('C:Program Files (x86)', 'mbam.exe|mbamgui.exe', True, 125)
MsgBox(0, '?????????', $FileList)
$FileList = StringSplit($FileList, @CRLF, 1)
_ArrayDisplay($FileList, UBound($FileList)&' - RegExp')

But it doesn't return anything.. what have i missed?

Edit even running the one you posted unaltered returns nothing either

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

'mbam.exe|mbamgui.exe' - it's files, look for them using _FileSearch will be faster.

first try to play with _FileSearch_Gui_Test.au3

using _PathSearch need to change the mask of '*mbam.exe |*mbamgui.exe'

Edited by AZJIO

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

there we go

I knew it would be something stupid im doing lol

PathSearch will hopefully be usefull to me because i can search for more than one file to guarentee its installed but return the path if they exist, which i can feed to another function

Is wildcards in the path possible? ie: Program*

Im aware i can use @ProgramFilesDir, i was just curious?

благодарность

Jez

Edited by Chimaera

Share this post


Link to post
Share on other sites

Chimaera

_FileSearch - searches for file names

_FileSearch(@WindowsDir, '*yste*')

C:WINDOWSsystem32configsystem.LOG

_PathSearch searches for text in a file path, and allow the ""

_PathSearch(@WindowsDir, '*yste*')

C:WINDOWSsystem32shell32.dll

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

for functions _FO_FileSearch, _FO_FolderSearch

$sLocale - Symbols of the local language (any non-Latin), to ignore the case when searching

$FileList=_FO_FileSearch($Path, '*Пример*', True, 125, 3, 1, 1, 'А-яЁё')

Update

;$sLocale - case sensitive.

; |0 - not case sensitive (only for 'A-z'), by default.

; |1 - case sensitive (for any characters)

; |<symbols> - not case sensitive, specified range of characters from local languages. For example 'А-яЁё'. 'A-z' is not required, they are enabled by default.

Edited by AZJIO

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now