Sign in to follow this  
Followers 0
NoMercy

File Searcher

21 posts in this topic

#1 ·  Posted (edited)

Hello guys... im trying to find(i need source code)/make a program that searches for a specific file on the hard disk without specifying the path....

for example to search for a .doc file on all the hard disk.

can any1 point me in the right direction please? i`ve spent 2days searching but didnt find anything on the net.

-tnx

Edited by NoMercy

Share this post


Link to post
Share on other sites



Look up

_FileListToArray()

_ArraySearch()

Easily done.


Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

ill try.. tnx.. if anyone else has anymore suggestions id be glad to hear them

Edited by NoMercy

Share this post


Link to post
Share on other sites

Search the keyword "Recursive" in the Example Scripts forum, you'll come up with a lot of examples and code.

Share this post


Link to post
Share on other sites

i think im onto something now... tnx Authenticity...

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

still cant find what i need...

i need a program that for example searches for all .doc and writes them into a file...

Edited by NoMercy

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Make the functions mentioned to create an filelist array from a folder, then go through it to isolate all the .doc files.

Edited by Inverted

Share this post


Link to post
Share on other sites

Give my program "SMF" a try :)...

my god its tooo complicated lol... i just need a simple script...

Share this post


Link to post
Share on other sites

Make the functions mentioned to create an filelist array from a folder, then go through it to isolate all the .doc files.

how can i do that? pls help im not that good with autoit... im still learning... if you have some time pls show me how.

Share this post


Link to post
Share on other sites

any ideas guys? i rly need this to work... pls

Share this post


Link to post
Share on other sites

I did a forum search for "recursive" ... came up with this on the first page:

http://www.autoitscript.com/forum/index.ph...mp;hl=recursive

I found at least 2 working examples out of several on this page. It seems they search everything first then give you results. So be patient when doing the search.

Share this post


Link to post
Share on other sites

ye i saw them and used the same concept but i still cant find what i need ... :)

Share this post


Link to post
Share on other sites

This one worked for me:

#include <File.au3>
#include <Array.au3>

Global $sRet
Local $sPath = @WindowsDir
Local $sFindFile = "calc.exe"

$aRetArray =  _FindPathName($sPath, $sFindFile)
_ArrayDisplay($aRetArray)


; Searches all subfolders of $sPath for $sFindFile (* and ? wildcards accepted)
; Returns an array containing full path and name of all matches.
; Number of matches is in zero index of array
Func _FindPathName($sPath, $sFindFile)
    Local $sSubFolderPath, $iIndex, $aFolders
    $search = FileFindFirstFile($sPath & "\" & $sFindFile)
    $aFolders = _FileListToArray($sPath, "*", 2)
    While 1
        $file = FileFindNextFile($search)
        If @error Then
            ExitLoop
        Else
            $sRet &= $sPath & "\" & $file & "|"
        EndIf
    WEnd
    FileClose($search)
    For $iIndex = 1 To $aFolders[0]
        $sSubFolderPath = $sPath & "\" & $aFolders[$iIndex]
        $aFoldersSubs = _FileListToArray($sSubFolderPath, "*", 2)
        If IsArray($aFoldersSubs) Then _FindPathName($sSubFolderPath, $sFindFile)
    Next
    Return StringSplit(StringTrimRight($sRet,1), "|")
EndFunc  ;==>_FindPathName

What isn't working for you?

Share this post


Link to post
Share on other sites

Here's another, though a very weird, way to do it:

#include <constants.au3>
#include <Array.au3>

Dim $fileList[1]
$fileList[0] = ""

$searchString = InputBox("Enter search", "What files do you want to find?", "*.doc")
$cmd = 'dir \' & $searchString & ' /s | find /I "directory of"' 

$result = _CMDreturn($cmd)

If Not $result Or StringInStr($result, "File Not Found") Then
    MsgBox(0, "", "No Files Found!")
    Exit
EndIf

$directories = StringRegExp($result, '[a-zA-Z]:\\[^/:*?"<>|]*[\r\n]', 3)

For $i = 0 To UBound($directories) - 1
    $dir = StringTrimRight($directories[$i],2)
    
    ;ConsoleWrite("$dir = " & $dir & @CRLF)
    If Not FileChangeDir($dir) Then
        ConsoleWrite("Unable to change directory to: " & $dir & @CRLF)
        ExitLoop
    EndIf
    
    $search = FileFindFirstFile($searchString)
    ;ConsoleWrite("$search = " & $search & ", and @error = " & @error & @CRLF)
    
    If $search = -1 Then ExitLoop
    While 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
        ;ConsoleWrite("$file = " & $file & @CRLF)
        _ArrayAdd($fileList, $dir & "\" & $file)
    WEnd
    FileClose($search)
Next

$fileList[0] = UBound($fileList) - 1
_ArrayDisplay($fileList)

Exit

Func _CMDreturn($sCommand) ; This function returns the output of a DOS command as a string
    Local $cmdreturn = ""
    Local $line, $stream
    $stream = Run(@ComSpec & " /c " & $sCommand, @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD)
    While 1 ; loop through the return from the command until there is no more
        $line = StdoutRead($stream)
        If @error Then ExitLoop
        $cmdreturn &= $line
    WEnd
    Return $cmdreturn
EndFunc   ;==>_CMDreturn

It's buggy but works for your purpose, probably won't work 100% of the time either...but since we're on the subject and nothing else is working for you I figure why not post it?

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

ok im using this and its working :

but how can i copy all these .doc files to another destination or delete them (im using the FileMove() and the FileDelete() ) not sure what im doing wrong...

and tnx for the help ppl...

#include <File.au3>
#include <Array.au3>

Global $sRet
Local $sPath = "e:\"
Local $sFindFile = "*.doc"

$aRetArray =  _FindPathName($sPath, $sFindFile)
_ArrayDisplay($aRetArray)


; Searches all subfolders of $sPath for $sFindFile (* and ? wildcards accepted)
; Returns an array containing full path and name of all matches.
; Number of matches is in zero index of array
Func _FindPathName($sPath, $sFindFile)
    Local $sSubFolderPath, $iIndex, $aFolders
    $search = FileFindFirstFile($sPath & "\" & $sFindFile)
    $aFolders = _FileListToArray($sPath, "*", 2)
    While 1
        $file = FileFindNextFile($search)
        If @error Then
            ExitLoop
        Else
            $sRet &= $sPath & "\" & $file & "|"
            


         FileMove($sRet,"c:\")                               ;move files    
         FileDelete($sRet)                          ; Delete files

        

                         EndIf
    WEnd
    FileClose($search)
    For $iIndex = 1 To $aFolders[0]
        $sSubFolderPath = $sPath & "\" & $aFolders[$iIndex]
        $aFoldersSubs = _FileListToArray($sSubFolderPath, "*", 2)
        If IsArray($aFoldersSubs) Then _FindPathName($sSubFolderPath, $sFindFile)
    Next
    Return StringSplit(StringTrimRight($sRet,1), "|")
EndFunc;==>_FindPathName
Edited by NoMercy

Share this post


Link to post
Share on other sites

any ideas guys?

Share this post


Link to post
Share on other sites

$sRet contains string which is not a valid file name and thus doesn't exist. The pipe for example is not a valid file name character. Use MsgBox() or ConsoleWrite() to see what $sRet contains and then you'll understand.

Share this post


Link to post
Share on other sites

ok i managed to get it working... tnx for everything guys,,, and sorry for bothering you so much :)

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