Jump to content

Recommended Posts

Posted (edited)

Been leaching people's code so here something trivial to give back to community

(requires beta)

Any critique or question is most welcomed.

#include<Constants.au3>

;Uses dos command to recurse a folder indicated by $source_path
;Note: filtes can be added (ie searching for .mp3 change $source_path to
;$source_path   ="C:\Program Files\AutoIt3\*.mp3"


$source_path    ="C:\Program Files\AutoIt3"

$dir = RecurseDir($source_path)

MsgBox(0, "$dir", $dir)


func RecurseDir($source_path)
    
    Local $output, $var, $foo, $line_out, $line_stderr
    $var = @ComSpec&' /C dir "'&$source_path&'" /s /b /a-d'
    ConsoleWrite($var&@lf)
    
    
    $foo = run($var, $source_path, @SW_ENABLE, $STDERR_CHILD + $STDOUT_CHILD)
    
    $output=""
        While 1
        $line_out = StdoutRead($foo)
        If @error = -1 Then ExitLoop
            $output = $output&$line_out
        Wend
        
        While 1
            $line_stderr = StderrRead($foo)
            If @error = -1 Then ExitLoop
                        
            MsgBox(0, "ERROR of Greatest Proportions", "CodeSuck: "&$line_stderr)
            Exit
        Wend
        
        return $output
EndFunc

myCurseDir.au3

Edited by Gnomercy
Posted

Why not just use FileFindFirst and FindFileNext in nested loops to recurse folders? Then you would not have to deal with the console.

How would you do it if the tree you're searching is many folders deep without using recursion?

I think i can see the nested loop working on stuff one folder deep. But for trees like c:\program files where you don't know what you'll get I am not seeing it.

One problem that I am having with my method is how to efficiently break a paragraph of text into an array.

I tried using Stringsplit on @cr, I get funny squares when it's written to a dos text file. I am sure it has to do with the 2 char CRLF windows uses to end string.

I am currently writing the block of text to a file and reading it back in line by line. if anyone has a better solution I am game.

/blow whistle, throw a yellow flag i know this isn't tech support.. at least i did have a solution B)

Posted

Take a look at the findfiles.au3 on this site http://www.autoitscript.com/fileman/users/jdeb/jdeb_autoit_stuff.htm. Although it does not do exactly what you want I am pretty sure you could modify it to. It uses FileFindNext to search in sub directories and returns the results as an array. It is a lot more code than yours but it does not require external commands.

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
  • Recently Browsing   0 members

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