Jump to content

Search For Files


Recommended Posts

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
Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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

Link to comment
Share on other sites

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
Link to comment
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

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...