Jump to content

Getting Folder names?


 Share

Recommended Posts

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.

Link to comment
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
Link to comment
Share on other sites

#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.

 

Link to comment
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
Link to comment
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

Link to comment
Share on other sites

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

Link to comment
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.

 

Link to comment
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
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...