Jump to content

Need help searching all folders.


 Share

Recommended Posts

I have this script to search all folders within a path for files but I get an error that the variable is not an array, does someone know how to fix this? code posted below:

#include <File.au3>
RunFind("C:")
Func RunFind($RunPath)
    SearchPNG($RunPath)
    Fetchfolders($RunPath)
EndFunc

Func Fetchfolders($Path)
    Dim $FileList
    $FileList = _FileListToArray($Path,"*",2)
    For $i = 1 to $FileList[0]
        MoreDepth1($Path,$FileList[$i])
    Next
EndFunc

Func MoreDepth1($StartPath1,$PathPiece1)
    $FullPath1=$StartPath1&"\"&$PathPiece1
    SearchPNG($FullPath1)
    Dim $DepthList1
    $DepthList1 = _FileListToArray($FullPath1,"*",2)
        For $i1 = 1 to $DepthList1[0]
            MoreDepth2($FullPath1,$DepthList1[$i1])
        Next
EndFunc

Func MoreDepth2($StartPath2,$PathPiece2)
    $FullPath2=$StartPath2&"\"&$PathPiece2
    SearchPNG($FullPath2)
    Dim $DepthList2
    $DepthList2 = _FileListToArray($FullPath2,"*",2)
        For $i2 = 1 to $DepthList2[0]
            MoreDepth3($FullPath2,$DepthList2[$i2])
        Next
EndFunc

Func MoreDepth3($StartPath3,$PathPiece3)
    $FullPath3=$StartPath3&"\"&$PathPiece3
    SearchPNG($FullPath3)
    Dim $DepthList3
    $DepthList3 = _FileListToArray($FullPath3,"*",2)
        For $i3 = 1 to $DepthList3[0]
            MoreDepth4($FullPath3,$DepthList3[$i3])
        Next
EndFunc

Func MoreDepth4($StartPath4,$PathPiece4)
    $FullPath4=$StartPath4&"\"&$PathPiece4
    SearchPNG($FullPath4)
    Dim $DepthList4
    $DepthList4 = _FileListToArray($FullPath4,"*",2)
        For $i4 = 1 to $DepthList4[0]
            MoreDepth5($FullPath4,$DepthList4[$i4])
        Next
EndFunc

Func MoreDepth5($StartPath5,$PathPiece5)
    $FullPath5=$StartPath5&"\"&$PathPiece5
    SearchPNG($FullPath5)
EndFunc

Func SearchPNG($SearchPath)
    FileChangeDir($SearchPath)
    $Search = FileFindFirstFile("*.PNG")  
    While 1
        $File = FileFindNextFile($Search)
        If @error Then ExitLoop
        $FilePath = $SearchPath&"\"&$File
        ReplaceFile($FilePath)
    WEnd
    FileClose($search)
EndFunc

Func ReplaceFile($ReplaceFilePath);; This Function will later replace all pngs found with bitmap images.
    ToolTip($ReplaceFilePath,0,0)
    sleep(10)
EndFunc

Help me please :P

Edited by toonboon

[right]~What can I say, I'm a Simplistic person[/right]

Link to comment
Share on other sites

Perhaps my own version of it might help. :P

#include <GuiConstantsEx.au3>
#include <ListViewConstants.au3>

$GUI = GUICreate("Files Search", 500, 420)

GUICtrlCreateLabel("Path to search:", 20, 5, -1, 15)
$Path_Input = GUICtrlCreateInput("C:\", 20, 20, 460, 20)

GUICtrlCreateLabel("Search request:", 20, 55, -1, 15)
$Request_Input = GUICtrlCreateInput("*.txt", 20, 70, 460, 20)

$Search_Button = GUICtrlCreateButton("Search", 20, 100, 60, 20)
$ListView = GUICtrlCreateListView("Results", 20, 130, 460, 250)

$SearhInfo_Label = GUICtrlCreateLabel("", 110, 105, 370)
$SearhStatus_Label = GUICtrlCreateLabel("", 20, 383, 450, 40)

GUISetState(@SW_SHOW, $GUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Search_Button
            $sPath = GUICtrlRead($Path_Input)
            $sRequest = GUICtrlRead($Request_Input)
           
            GUICtrlSendMsg($ListView, $LVM_DELETEALLITEMS, 0, 0)
            GUICtrlSetData($SearhInfo_Label, "Please wait, seaching...")
           
            $aResults = _FileSearch($sPath, $sRequest, 1, 0, $SearhStatus_Label)
           
            If @error Then
                MsgBox(48, "Attention!", "No files found.", 0, $GUI)
            Else
                For $i = 1 To UBound($aResults)-1
                    GUICtrlCreateListViewItem($aResults[$i], $ListView)
                Next
               
                GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, -1)
            EndIf
           
            GUICtrlSetData($SearhStatus_Label, "")
            GUICtrlSetData($SearhInfo_Label, StringFormat("Done: %i files found.", UBound($aResults)-1))
    EndSwitch
WEnd

;================================================================================
;Flag = 1 search with recurse
;Flag <> 1 search without recurse
;
;$iRet = 1 return parent directory of the file path
;$iRet <> 1 return full file path
;
;$iStatus_CtrlID - If this is an id of the label control, the function will set the current status of the search
;
;On Failure set @error as following:
;   1 - $sPath is not a dir or it not exists (in this case returned -1).
;   2 - $sPath is empty dir.
;   3 - No files found in $sPath dir.
;
;On Seccess return an array with found files.
;================================================================================
Func _FileSearch($sPath, $sMask, $iFlag=0, $iRet=0, $iStatus_CtrlID=0)
    If Not StringInStr(FileGetAttrib($sPath), "D") Then Return SetError(1, 0, -1)
   
    Local $aRetPathArr[1], $sFindNextFile, $sCurrentPath, $aSubDirFindArr
    If StringInStr($sMask, "*") Then $sMask = StringReplace($sMask, "*.", "")
   
    $sPath = StringRegExpReplace($sPath, '\\+ *$', '\')
   
    Local $hSearch = FileFindFirstFile($sPath & "\*.*")
    If @error = 1 Then Return SetError(2, 0, 0)
    If $hSearch = -1 Then Return SetError(3, 0, 0)
   
    While 1
        $sFindNextFile = FileFindNextFile($hSearch)
        If @error = 1 Then ExitLoop
       
        If $iStatus_CtrlID Then _GUICtrlSetData($iStatus_CtrlID, $sPath)
       
        $sCurrentPath = $sPath & "\" & $sFindNextFile
       
        If $iFlag = 1 And StringInStr(FileGetAttrib($sCurrentPath), "D") Then
            $aSubDirFindArr = _FileSearch($sCurrentPath, $sMask, $iFlag, 0, $iStatus_CtrlID)
            If @error Then ContinueLoop
           
            For $i = 1 To $aSubDirFindArr[0]
                $aRetPathArr[0] += 1
                ReDim $aRetPathArr[$aRetPathArr[0]+1]
               
                $aRetPathArr[$aRetPathArr[0]] = $aSubDirFindArr[$i]
                If $iRet = 1 Then _
                    $aRetPathArr[$aRetPathArr[0]] = StringRegExpReplace($aRetPathArr[$aRetPathArr[0]], "\\[^\\]*$", "")
               
                If $iStatus_CtrlID Then _GUICtrlSetData($iStatus_CtrlID, $aSubDirFindArr[$i])
            Next
        Else
            If $sMask = "*" Or $sFindNextFile = $sMask Or StringRegExpReplace($sCurrentPath, '^.*\.', '') = $sMask Then
                $aRetPathArr[0] += 1
                ReDim $aRetPathArr[$aRetPathArr[0]+1]
               
                $aRetPathArr[$aRetPathArr[0]] = $sCurrentPath
                If $iRet = 1 Then $aRetPathArr[$aRetPathArr[0]] = $sPath
            EndIf
        EndIf
    WEnd
   
    FileClose($hSearch)
   
    If $aRetPathArr[0] = 0 Then Return SetError(3, 0, 0)
   
    Return $aRetPathArr
EndFunc

Func _GUICtrlSetData($iCtrlID, $sData)
    If GUICtrlRead($iCtrlID) <> $sData Then GUICtrlSetData($iCtrlID, $sData)
EndFunc
System task ---> My first GUICalculator v1.0 ---> My version of the calculatorNetZilla 1.0 --> Web browserEmail Sender --> You can Send emails with this without opening a web browser
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...