Sign in to follow this  
Followers 0
Aladdin

how to search for a specific file in a directory and all of it's sub directories?

7 posts in this topic

hi,

the title of my thread says what i need...

how to search for a specific file in a directory and all of it's sub directories?

and then get the full path of file found in output and move the file to C:\MovedFiles

file names are:

solo.mpg

ex.mpg

can any of you help me? searching the forum did not helped

:)


_______________________________

Share this post


Link to post
Share on other sites



Have a look in the help file under FileFindFirstFile, FileFindNextFile and FileExists.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

Have a look in the help file under FileFindFirstFile, FileFindNextFile and FileExists.

You can also use the 'Search' function on the forum to find a pretty good assortment of scripts that do what you want in a variety of ways.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

hi,

the title of my thread says what i need...

how to search for a specific file in a directory and all of it's sub directories?

and then get the full path of file found in output and move the file to C:\MovedFiles

file names are:

solo.mpg

ex.mpg

can any of you help me? searching the forum did not helped

:)

You could use the script located here

http://www.autoitscript.com/forum/index.ph...st&p=632102

then use FileMove () function to move the file or files found.

To get the file name from the full path and file name string you can use

; Get File name

$sFile = "c:\Program Files\Autio\AutoIt3.chm"

$sName = StringRegExpReplace($sFile, "^.*\\", "") ; Returns FileName only

 MsgBox(0, "Extension", $sName)

Share this post


Link to post
Share on other sites

Thanks all for the help, now only the last problem is that searched fies are not going to be moved or deleted.

i have the problem here:

Global $sRet
Local $sPath = @HomeDrive
Local $sFindFile = "solo.mpg"

$aRetArray =  _FindPathName($sPath, $sFindFile)
FileDelete($aRetArray)oÝ÷ Ø[¥Ç+b²«y«­¢+Øì}¥±MÉ  ±ÐíAÑ ¹5ͬÐì°±Ðí=ÁÑ¥½¸ À´¹½Éµ°°Ä´ÉÕÉÍ¥Ù¤Ðì¤(ìIÑÕɹÌÉÉ严ѡÈÉÉä½¥±Ì¡Õ±°ÁÑ ¤Ý¡É¸¸¸(ìÉÉålÁt¥Ì¹ÕµÈ½¥±Ì¸(ìÉÉålÁtôÀ¥¹½Ñ¡¥¹½Õ¹¸(ì(ìa5A1UM(ì´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´((¥¹±Õ±Ðí¥±¹ÔÌÐì(¥¹±Õ±ÐíÉÉä¹ÔÌÐì()±½°ÀÌØíÍIÐ)1½°ÀÌØíÍAÑ ô!½µÉ¥Ù)1½°ÀÌØíÍ¥¹¥±ôÅÕ½Ðíͽ±¼¹µÁÅÕ½Ðì((ÀÌØíIÑÉÉäô}¥¹AÑ¡9µ ÀÌØíÍAÑ °ÀÌØíÍ¥¹¥±¤(í}ÉÉå¥ÍÁ±ä ÀÌØíIÑÉÉä¤(졽ÜѼ±Ñ¥±ÌÍÉ¡ü)¥±±Ñ ÀÌØíIÑÉÉä¤ìMɡ̱°ÍÕ½±É̽ÀÌØíÍAÑ ½ÈÀÌØíÍ¥¹¥± ¨¹üÝ¥±ÉÌÁѤ(ìyyyyyyyyyyyyyyyyyyyyyyyyyyx(ìIÑÕɹ̸ÉÉ佹ѥ¹¥¹Õ±°ÁÑ ¹¹µ½±°µÑ¡Ì¸(ì9յȽµÑ¡Ì¥Ì¥¸éɼ¥¹à½ÉÉä)Õ¹}¥¹AÑ¡9µ ÀÌØíÍAÑ °ÀÌØíÍ¥¹¥±¤(1½°ÀÌØíÍMÕ½±ÉAÑ °ÀÌØí¥%¹à°ÀÌØí½±ÉÌ(ÀÌØíÍÉ ô¥±¥¹¥ÉÍÑ¥± ÀÌØíÍAÑ µÀìÅÕ½ÐìÀäÈìÅÕ½ÐìµÀìÀÌØíÍ¥¹¥±¤(ÀÌØí½±ÉÌô}¥±1¥ÍÑQ½ÉÉä ÀÌØíÍAÑ °ÅÕ½Ðì¨ÅÕ½Ðì°È¤(]¡¥±Ä(ÀÌØí¥±ô¥±¥¹9áÑ¥± ÀÌØíÍÉ ¤(%ÉɽÈQ¡¸(á¥Ñ1½½À(±Í(ÀÌØíÍIеÀìôÀÌØíÍAÑ µÀìÅÕ½ÐìÀäÈìÅÕ½ÐìµÀìÀÌØí¥±µÀìÅÕ½ÐíðÅÕ½Ðì(¹%(]¹(¥±
±½Í ÀÌØíÍÉ ¤(½ÈÀÌØí¥%¹àôÄQ¼ÀÌØí½±ÉÍlÁt(ÀÌØíÍMÕ½±ÉAÑ ôÀÌØíÍAÑ µÀìÅÕ½ÐìÀäÈìÅÕ½ÐìµÀìÀÌØí½±ÉÍlÀÌØí¥%¹át(ÀÌØí½±ÉÍMÕÌô}¥±1¥ÍÑQ½ÉÉä ÀÌØíÍMÕ½±ÉAÑ °ÅÕ½Ðì¨ÅÕ½Ðì°È¤(%%ÍÉÉä ÀÌØí½±ÉÍMÕ̤Q¡¸}¥¹AÑ¡9µ ÀÌØíÍMÕ½±ÉAÑ °ÀÌØíÍ¥¹¥±¤(9áÐ(IÑÕɸMÑÉ¥¹MÁ±¥Ð¡MÑÉ¥¹QÉ¥µI¥¡Ð ÀÌØíÍIаĤ°ÅÕ½ÐíðÅÕ½Ðì¤)¹Õ¹ìôôÐí}¥¹AÑ¡9µ

_______________________________

Share this post


Link to post
Share on other sites

The function return an array. You cannot use it like FileDelete($aRetArray).

Try it:

Global $sRet
Local $sPath = @HomeDrive
Local $sFindFile = "solo.mpg"

$aRetArray =  _FindPathName($sPath, $sFindFile)
For $x = 1 To $aRetArray[0]
    FileDelete($aRetArray[$x])
Next

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Try this.

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

Global $sRet
Local $sPath = @HomeDrive
Local $sFindFile = "solo.mpg"
Local $MoveToDir = "C:\MovedFiles"
$aRetArray = _FindPathName($sPath, $sFindFile)
;_ArrayDisplay($aRetArray)

If $aRetArray[1] = "" Then
    MsgBox(0, "", "File not found")
Else
    For $iIndex = 1 To UBound($aRetArray) - 1; Work through contents of array
        FileMove($aRetArray[$iIndex], $MoveToDir & "\" & StringRegExpReplace($aRetArray[$iIndex], "^.*\\", ""))
        FileDelete($aRetArray[$iIndex]); Delete file at found location
    Next
EndIf

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

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