Sign in to follow this  
Followers 0
SlimShady

Search For Files

10 posts in this topic

#1 ·  Posted (edited)

AutoIt is the best. Thank you for creating this amazing script language and provide it free for everybody.

I created a script that searches for files. I'm using the FileFindFirstFile function. There are two problems:

- it only searches in the directory you specify and doesn't search through the subfolders.

- it only returns the filename and not the full path to the file.

It would be great if you would/could add the missing functionality I mentioned above.

Thanks again.

$SearchWord = InputBox("Search", "Enter a word to search for:" , "", "" , 200, 100)
$SearchLocation = FileSelectFolder("Choose a folder to search in:", "", 0)

$search = FileFindFirstFile($SearchLocation & "\" & $SearchWord)

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

$Results = FileOpen(@ScriptDir & "\results.txt", 2)

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    FileWriteLine($Results, $file)
WEnd

; Close the search handle
FileClose($search)
FileClose($Results)

Run("notepad " & @ScriptDir & "\results.txt")
Exit

EDIT: The working script I made is available: here.

Edited by SlimShady

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

here's a script posted a while ago to scans through all subdirs and counts files sizes... just modify it to just look for a file....

EDIT: Updated to the correct link:http://www.hiddensoft.com/forum/index.php?...findpost&p=6919

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

- it only returns the filename and not the full path to the file.

If you are searching thru a folder, you probably already know the path of the folder.

If you don't, then you're way off :D

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I wanted to make a replacement for Windows filesearch.

Ezzetabi made me curious when he said something about: dir /s /b

So I used that; Some statistics:

- Whole C-drive listed in a 2,85 MB textfile in about 5 to 10 seconds

- i searched for the letters zip; found 376 zip files in exactly 10 seconds (really!)

My script:

- it's interactive; asks for word (letters) to search for and which drive/folder

- It can show you every result in a dialogbox which asks you:

"Do you want to locate the file now" <- automatically!

OR

- It hides itself, searches and shows the results in a textfile when it's done

Here it is, enjoy!

EDIT: The working script I made is available: here.

Edited by SlimShady

Share this post


Link to post
Share on other sites

Btw, I think Micro$oft should use my method :D.

Much quicker.

Share this post


Link to post
Share on other sites

I wish i could make something i could actually use... but nice program


-Brett

Share this post


Link to post
Share on other sites

I got this from Larry a while back

SearchRecursive(<path with trailinbg slash>, <file search string>)

usage:

$FileArray = SearchRecursive( "C:\", "*.AU3" )

If Not @error

;$FileArray[] now contains a zero based

;array of files found by SearchRecursive().

;Use "UBound()" and a "For / Next" loop

;to process the results.

EndIf

Exit

#include "SearchRecursive.au3" ;ADD at the bottom of your script

Func SearchRecursive($SR_sRoot,$SR_sSearch)

$SR_aReturn=""

$SR_iFiles = 0

$SR_sDirList = ""

$SR_sFileList = ""

While Not @error

$SR_sBuffer = FileFindFirstFile($SR_sRoot & "*.*")

While Not @error

If $SR_sBuffer <> "." And $SR_sBuffer <> ".." Then

If StringInStr(FileGetAttrib($SR_sRoot & $SR_sBuffer),"D") Then

$SR_sDirList = $SR_sDirList & $SR_sRoot & $SR_sBuffer & "*"

EndIf

EndIf

$SR_sBuffer = FileFindNextFile()

Wend

$SR_sBuffer = FileFindFirstFile($SR_sRoot & $SR_sSearch)

While Not @error

$SR_sFileList = $SR_sFileList & $SR_sRoot & $SR_sBuffer & "*"

$SR_iFiles = $SR_iFiles + 1

$SR_sBuffer = FileFindNextFile()

Wend

$SR_iDirDelim = StringInStr($SR_sDirList,"*")

If $SR_iDirDelim Then

$SR_sRoot = StringLeft($SR_sDirList,$SR_iDirDelim-1) & "\"

$SR_sDirList = StringTrimLeft($SR_sDirList,$SR_iDirDelim)

Else

SetError(1)

EndIf

Wend

If $SR_iFiles Then

DIM $SR_aReturn[$SR_iFiles]

For $SR_iElement = 0 to $SR_iFiles-1

$SR_iDelimPos = StringInStr($SR_sFileList,"*")

$SR_aReturn[$SR_iElement] = StringLeft($SR_sFileList,$SR_iDelimPos-1)

$SR_sFileList = StringTrimLeft($SR_sFileList,$SR_iDelimPos)

Next

Else

SetError(1)

EndIf

Return $SR_aReturn

EndFunc


Only $2.00 with Resale Rights How to Block Better for Martial Artists and NonMartial Artistshttp://kirkhamsebooks.com/MartialArts/Bloc...tterEbook_m.htm

Share this post


Link to post
Share on other sites

Can someone test the script from Larry (above)?

How much time does it take to find something and how many results?

I'm currently implementing the ability for multiple keywords in one inputbox.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I did it. It wasn't very hard to make this script search for multiple words.

Example:

It tries to match all the words in the full path of the file.

If you have a file with the path:

C:\Program Files\Test\file.exe

It will match if you enter:

  • .exe
  • program file.exe
  • file.exe
  • files file.exe
  • .exe test file
EDIT: The working script I made is available: here. Edited by SlimShady

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
Sign in to follow this  
Followers 0