Sign in to follow this  
Followers 0
Who

Search for a file ?

7 posts in this topic

Are there any way for me to search for a file in all drive with AutoIT and return the full path to it ? Thanks very much. :whistle:

Share this post


Link to post
Share on other sites



Are there any way for me to search for a file in all drive with AutoIT and return the full path to it ? Thanks very much. :whistle:

You can search a directory, and make that recursive to search all directories on a drive.

To do all drives, start from the help file with DriveGetDrive(), and step through the list of drives.

:lmao:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I have tried Larry's script :

http://www.autoitscript.com/forum/index.php?showtopic=2753

If I use DriveGetDrive() then I will get a list of drives : C:\ D:\ E:\ ... but the var $szRoot in Larry's script support only one drive. Can you give me suggestion please :whistle: ?

Share this post


Link to post
Share on other sites

I have tried Larry's script :

http://www.autoitscript.com/forum/index.php?showtopic=2753

If I use DriveGetDrive() then I will get a list of drives : C:\ D:\ E:\ ... but the var $szRoot in Larry's script support only one drive. Can you give me suggestion please :whistle: ?

To use Larry's function, call _FileSearch($Target, 1) once for each drive with the variable $Target set to each drive's root in turn. A For/Next loop is the most stright-forward way to do that.

Code something up and post it. If it doesn't work, you'll get help with it, but the forum isn't likely to write it for you.

:lmao:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

; _FileSearch( <Path and Mask>, <Option (0 - normal, 1- recursive)>)
; Returns array. Either Array of files (full path) where...
; Array[0] is number of files.
; Array[0] = 0 if nothing found.
;
; EXAMPLE USAGE
;--------------------------------------------

$var = DriveGetDrive("all")
If NOT @error Then
For $ii = 1 to $var[0]
$a = _FileSearch($var[$ii]&"\","file.txt",1)
If $a[0] > 0 Then
    For $i = 1 to $a[0]
         MsgBox(4096,"",$a[$i])
     Next
EndIf
Next
EndIf
;--------------------------------------------

Func _FileSearch($szRoot, $szMask,$nOption)
   ;$szRoot = ""
    $hFile = 0
    $szBuffer = ""
    $szReturn = ""
    $szPathList = "*"
    Dim $aNULL[1]

#cs
    If Not StringInStr($szMask,"\") Then
         $szRoot = "C:\"
    Else
         While StringInStr($szMask,"\")
              $szRoot = $szRoot & StringLeft($szMask,StringInStr($szMask,"\"))
              $szMask = StringTrimLeft($szMask,StringInStr($szMask,"\"))
         Wend
    EndIf
#ce

    If $nOption = 0 Then
         _FileSearchUtil($szRoot, $szMask, $szReturn)
    Else
         While 1
              $hFile = FileFindFirstFile($szRoot & "*.*")
              If $hFile >= 0 Then
                   $szBuffer = FileFindNextFile($hFile)
                   While Not @ERROR
                        If $szBuffer <> "." And $szBuffer <> ".." And _
                             StringInStr(FileGetAttrib($szRoot & $szBuffer),"D") Then _
                             $szPathList = $szPathList & $szRoot & $szBuffer & "*"
                        $szBuffer = FileFindNextFile($hFile)
                   Wend
                   FileClose($hFile)
              EndIf
              _FileSearchUtil($szRoot, $szMask, $szReturn)
              If $szPathList == "*" Then ExitLoop
              $szPathList = StringTrimLeft($szPathList,1)
              $szRoot = StringLeft($szPathList,StringInStr($szPathList,"*")-1) & "\"
              $szPathList = StringTrimLeft($szPathList,StringInStr($szPathList,"*")-1)
         Wend
    EndIf
    If $szReturn = "" Then
         $aNULL[0] = 0
         Return $aNULL
    Else
         Return StringSplit(StringTrimRight($szReturn,1),"*")
    EndIf
EndFunc

Func _FileSearchUtil(ByRef $ROOT, ByRef $MASK, ByRef $RETURN)
    $hFile = FileFindFirstFile($ROOT & $MASK)
    If $hFile >= 0 Then
         $szBuffer = FileFindNextFile($hFile)
         While Not @ERROR
              If $szBuffer <> "." And $szBuffer <> ".." Then _
                   $RETURN = $RETURN & $ROOT & $szBuffer & "*"
              $szBuffer = FileFindNextFile($hFile)
         Wend
         FileClose($hFile)
    EndIf
EndFunc

I have tried this and it returned results from all drive :

C:\bak\file.txt
D:\file.txt
D:\Home\Documents\file.txt

That's good but can you help me to get out the full path like this into a new array please :

C:\bak\
D:\
D:\Home\Documents\

Thanks :whistle:

Share this post


Link to post
Share on other sites

Ok, I have figured it out and it now works like a charm. Thank you very much for your suggestion :lmao:

p/s : I just only ask for suggestions, I doesn't mean to ask for a script writer :whistle: if I have chance to try myself

Share this post


Link to post
Share on other sites

Ok, I have figured it out and it now works like a charm. Thank you very much for your suggestion :lmao:

p/s : I just only ask for suggestions, I doesn't mean to ask for a script writer :whistle: if I have chance to try myself

You're welcome, and welcome to AutoIt!

I was only pointing out how this forum works. It wasn't meant to sound hostile.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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