Jump to content

Folder Name


Doppio
 Share

Recommended Posts

  • Moderators

Folder name of what (where the script is, what your looking at, etc...)? And how do you want to impliment it?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Folder name of what (where the script is, what your looking at, etc...)? And how do you want to impliment it?

I backed up about a 100 folders from different users to an external drive, every folder has the user's name as a reference. I would like some script that would read all the folder's names into a combobox. I hope you understand my question.

Thank you

Link to comment
Share on other sites

  • Moderators

Here this may help you... it returns an array of the names of the folder in that file... I used a test folder to test it on my desktop with 200 folders in it.

#include <array.au3>
Local $Folder2Search = FileFindFirstFile(@DesktopDir & "\Test Folder\*.*")  
Local $test = GetClientNames($Folder2Search)
_ArrayDisplay($test, 'Names In An Array')
Func GetClientNames($s_SearchFolder)
    Local $nArray
    Local $Folders
    While 1
        $Folders = $Folders & FileFindNextFile($s_SearchFolder) & Chr(01)
        If @error Or StringRight($Folders, 2) = Chr(01) & Chr(01) Then ExitLoop
    WEnd
    $nArray = StringSplit(StringTrimRight($Folders, 2), Chr(01))
    FileClose($s_SearchFolder)
    Return $nArray
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Here this may help you... it returns an array of the names of the folder in that file... I used a test folder to test it on my desktop with 200 folders in it.

#include <array.au3>
Local $Folder2Search = FileFindFirstFile(@DesktopDir & "\Test Folder\*.*")  
Local $test = GetClientNames($Folder2Search)
_ArrayDisplay($test, 'Names In An Array')
Func GetClientNames($s_SearchFolder)
    Local $nArray
    Local $Folders
    While 1
        $Folders = $Folders & FileFindNextFile($s_SearchFolder) & Chr(01)
        If @error Or StringRight($Folders, 2) = Chr(01) & Chr(01) Then ExitLoop
    WEnd
    $nArray = StringSplit(StringTrimRight($Folders, 2), Chr(01))
    FileClose($s_SearchFolder)
    Return $nArray
EndFunc

Nice. Here's a sample combobox script, can you show me how to write the array to the combobox?

thank you.

#include <GUIConstants.au3>
#include <GuiCombo.au3>
#include <array.au3>
#NoTrayIcon



; == GUI generated with Koda ==
$Form1 = GUICreate("AForm1", 622, 441, 192, 125)
$Combo1 = GUICtrlCreateCombo("", 216, 168, 177, 21)

GUISetState(@SW_SHOW)



While 1
                                         
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;;;;;
    EndSelect
WEnd
Exit


Local $Folder2Search = FileFindFirstFile("H:\EUB\*.*")  
Local $test = GetClientNames($Folder2Search)
_ArrayDisplay($test, 'Names In An Array')

Func GetClientNames($s_SearchFolder)
    Local $nArray
    Local $Folders
    While 1
        $Folders = $Folders & FileFindNextFile($s_SearchFolder) & Chr(01)
        If @error Or StringRight($Folders, 2) = Chr(01) & Chr(01) Then ExitLoop
    WEnd
    $nArray = StringSplit(StringTrimRight($Folders, 2), Chr(01))
    FileClose($s_SearchFolder)
    Return $nArray
EndFunc
Link to comment
Share on other sites

Nice. Here's a sample combobox script, can you show me how to write the array to the combobox?

thank you.

#include <GUIConstants.au3>
#include <GuiCombo.au3>
#include <array.au3>
#NoTrayIcon
; == GUI generated with Koda ==
$Form1 = GUICreate("AForm1", 622, 441, 192, 125)
$Combo1 = GUICtrlCreateCombo("", 216, 168, 177, 21)

GUISetState(@SW_SHOW)
While 1
                                         
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
;;;;;;;
    EndSelect
WEnd
Exit
Local $Folder2Search = FileFindFirstFile("H:\EUB\*.*")  
Local $test = GetClientNames($Folder2Search)
_ArrayDisplay($test, 'Names In An Array')

Func GetClientNames($s_SearchFolder)
    Local $nArray
    Local $Folders
    While 1
        $Folders = $Folders & FileFindNextFile($s_SearchFolder) & Chr(01)
        If @error Or StringRight($Folders, 2) = Chr(01) & Chr(01) Then ExitLoop
    WEnd
    $nArray = StringSplit(StringTrimRight($Folders, 2), Chr(01))
    FileClose($s_SearchFolder)
    Return $nArray
EndFunc
I found the answer :lmao:

Getting folder names

Link to comment
Share on other sites

I found the answer :lmao:

Getting folder names

I looked for that post also...

#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

the one i wrote above... worked well for me ( it was in the post )

8)

NEWHeader1.png

Link to comment
Share on other sites

  • 5 weeks later...

#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)
$allocated = _GUICtrlComboInitStorage($Combo, 100, 50)
$ret = _GUICtrlComboAddDir($Combo,"D,E",@MyDocumentsDir & "\*")
_GUICtrlComboDeleteString($Combo,0)
$Btn_Exit = GuiCtrlCreateButton("Exit", 150, 180, 90, 30)
$Status = GUICtrlCreateLabel("",0,234,392,20,BitOR($SS_SUNKEN,$SS_CENTER))
GUICtrlSetData($Status,"Pre-Allocated Memory For: " & $allocated & " Items, Folders Added To ComboBox: " & _GUICtrlComboGetCount($Combo))
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

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