Jump to content
Sign in to follow this  
mattfaust

Find subdirectories?

Recommended Posts

mattfaust

How can I find what sub-directories exist in a path?

I have a small backup script that works, but now I want it to only backup directories it hasnt found yet instead of all of em

Thanks

Share this post


Link to post
Share on other sites
mattfaust

A quick look in the help file found this

FileFindFirstFile()

yeah, I cant see how to make it return only directories

Share this post


Link to post
Share on other sites
Malkey

This may help you.

#include <Array.au3>

;An array of sub-directories not to be backed up this time.
Local $aPrevBkUp[2] = ["C:\Program Files\AutoIt3\Examples\GUI", _
        "C:\Program Files\AutoIt3\Examples\GUI\Advanced"]

;List of all sub-directories
Local $sSortedDir = StringStripWS(_GetDOSOutput('dir "C:\Program Files\AutoIt3\" /A:-A /S /B /O:N'), 3)
;ConsoleWrite(_GetDOSOutput('dir /?') & @CRLF) ; Dir help
ConsoleWrite($sSortedDir & @CRLF)

;Remove sub-directories not requiring backup
For $i = 0 To UBound($aPrevBkUp) - 1
    If StringInStr($sSortedDir, $aPrevBkUp[$i]) <> 0 Then $sSortedDir = StringReplace($sSortedDir, $aPrevBkUp[$i] & @CRLF, "")
Next

;Change string of sub-directories into an array of sub-directories.
Local $aNewBkUpDirs = StringSplit($sSortedDir, @CRLF, 3)

_ArrayDisplay($aNewBkUpDirs)




; http://www.autoitscript.com/forum/index.php?showtopic=108678&view=findpost&p=765520
; http://www.autoitscript.com/forum/index.php?showtopic=106254&view=findpost&p=750640
Func _GetDOSOutput($command)
    Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, 2 + 4)
    While 1
        $text &= StdoutRead($Pid, False, False)
        If @error Then ExitLoop
        Sleep(10)
    WEnd
    Return $text
EndFunc ;==>_GetDOSOutput

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.