Sign in to follow this  
Followers 0
D4rk^S0ul

Getting Folder names?

12 posts in this topic

Is it possible to get all the folder names in a defined folder? I have searched the forum but i couldnt find anything that i could use

Share this post


Link to post
Share on other sites



Capture the output (of which there are several methods) from the following DOS cmd ..

dir /ad /b

BTW .. to capture all child folders as well, use this instead ..

dir /ad /b /s

:P

Share this post


Link to post
Share on other sites

The popular way to do this has been with FindFind... and FileGetAttrib, here's a thread with an example.

To find this I searched the forum for +FileFind* and +FileGetAttrib*


Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites

Hi,

To expand on trids' remark;

try this (cd link in my sig to doscoms.au3)

;DosSwitchesFolderExample1.au3

#include<DOSComs.au3>

$Folder=@ScriptDir

$t = TimerInit()

;_DIR($Folder, "/4/O-g/O-d/n/b/s")

; **============This lists all folders and sub-folders in $Folder directory

_DIR($Folder, "/ad/s")

ConsoleWrite(Timerdiff($t) & @CRLF)

;@TempDir & "\FileList.tmp"

RunWait("Notepad.exe " &@TempDir & "\FileList.tmp",@ScriptDir,@SW_SHOW)

Best, Randall

Share this post


Link to post
Share on other sites

Thx for the help but is there anyway i can do it in the script so i can return the answer as a defined name? So i can make a combo of the names.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

#include <GuiConstants.au3>
#include <GuiCombo.au3>

Opt('MustDeclareVars',1)

Dim $Combo,$ret,$Btn_Exit,$Status,$msg,$allocated

GuiCreate("ComboBox Add Dir", 392, 254)

$Combo = GuiCtrlCreateCombo("", 70, 10, 270, 100,$CBS_SIMPLE)
$ret = _GUICtrlComboAddDir($Combo,"D,E", "*.*")
$Btn_Exit = GuiCtrlCreateButton("Exit", 150, 180, 90, 30)
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
            ExitLoop
    EndSelect
WEnd
Exit

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Thx for the help but is there anyway i can do it in the script so i can return the answer as a defined name? So i can make a combo of the names.

You could probably addapt this

#include <file.au3>
processFolder(@scriptDir)

func processFolder($path)

    local $fileHandle, $file, $dirHandle, $dir

    local const $FILESPEC = "*.*"
; debug("Starting with " & $path)

; debug("Going to search for " & $path & "\" & $FILESPEC)
    $fileHandle = fileFindFirstFile($path & "\" & $FILESPEC)
    if ($fileHandle <> -1) then
        while (1)
            $file = fileFindNextFile($fileHandle)
            if (@error = 1) then exitLoop
            if ($file = "." or $file = "..") then continueLoop
            $file = $path & "\" & $file
            if (isFolder($file)) then continueLoop
           ;debug("Found file " & $file)
                  
         
         
        wEnd
        fileClose($fileHandle)
     

    endIf

; debug("Going to search for subfolders")
    $dirHandle = fileFindFirstFile($path & "\*.*")
    if ($dirHandle <> -1) then
        while (1)
            $dir = fileFindNextFile($dirHandle)
            if (@error = 1) then exitLoop
            if ($dir = "." or $dir = "..") then continueLoop
            $dir = $path & "\" & $dir
            if (not(isFolder($dir))) then continueLoop
      debug("Found subfolder " & $dir)
            processFolder($dir)
        wEnd
        fileClose($dirHandle)
    endIf

endFunc

func isFolder($path)
    if stringInStr(fileGetAttrib($path), "D") then return 1
    return 0
endFunc

func debug($text)
    msgBox(0x40, "processFolder()", $text)
endFunc

Share this post


Link to post
Share on other sites

Thx for the help but is there anyway i can do it in the script so i can return the answer as a defined name? So i can make a combo of the names.

From my script, simply loop through filereadline from the answerFile?...

randall

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

another choice is FileListToArray()

example

#include <GUIConstants.au3>
#Include <File.au3>

$Location = @ProgramFilesDir

$FileList=_FileListToArray($Location, "*.*", 2)
If (Not IsArray($FileList)) and (@Error=1) Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf


GUICreate("My GUI combo"); will create a dialog box that when displayed is centered

GUICtrlCreateCombo ("", 10,10); create first item
For $x = 1 to $FileList[0]
    GUICtrlSetData(-1,$FileList[$x],"|"); add other item send set a new default
Next
GUISetState ()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

$ret = _GUICtrlComboAddDir($Combo,"D,E", "*.*")

D = DIRECTORY - Includes subdirectories. Subdirectory names are enclosed in square brackets ([ ]).

E = EXCLUSIVE - Includes only files with the specified attributes. By default, read-write files are listed even if READWRITE is not specified.

"*.*" - can have a path to look in also i.e. c:\*.*


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

alot of good replies; i just wanted to toss in another alternative... this is a recursive file lister that i made as an example for another thread, currently it starts at root of c and lists all sub files and folders and their size. if you change 3-4 lines, you should be able to create an output file of just the directories, and make an input box/fileopendialog()/etc to take user input on where to start....

$tosearch = "C:"
$output = FileOpen("c:\filelist.txt",2)
Global $deep = 0
$start = TimerInit()
RecFileSearch($tosearch)
FileClose($output)
MsgBox(0,"done","it only took " & int(TimerDiff($start)/1000) & " seconds")
Func RecFileSearch($current)
    $deep = $deep +1
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
    Dim $file = FileFindNextFile($search)
    If @error Or StringLen($file)<1 Then ExitLoop
    FileWriteLine($output,$current & "\" & $file & "     " & FileGetSize($file))
    If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then RecFileSearch($current & "\" & $file)
    WEnd
    FileClose($search)
EndFunc

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

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