Jump to content

Directory list to combobox - need help


vacko
 Share

Recommended Posts

Hi,

in my script I need list all directories in given path (not recursive). All directories are named according to some structure, I need extract some, let's call it "short name", from directory name and use it in combo box. After user select "short name" from combo box, script should return full path to corresponding directory.

Here is example of directory structure

..City1_Country_some_other_strings

..City2_Country_some_other_strings

..City3_Country_some_other_strings

..City4_City5_Country_some_other_strings

..City6_City7_City8_City9_Country_some_other_strings

"City" is some word which is always different and which I want use in combo box (I call it "short name"), but often there is more this words (separated by _)

"Country" is word which is always present (and still same) in directory name, but I no need it

some_other_strings are some other strings (letters, numbers, symbols), which I also no need

My script is already working, but it show only first short name in combo box.

How to show all short names (and return correct path) ?

In my example "output",

first column is what I want display in combobox, second column is path should be returned by script

City1 full_pathCity1_Country_some_other_strings

City2 full_pathCity2_Country_some_other_strings

City3 full_pathCity3_Country_some_other_strings

City4 full_pathCity4_City5_Country_some_other_strings

City5 full_pathCity4_City5_Country_some_other_strings

City6 full_pathCity6_City7_City8_City9_Country_some_other_strings

City7 full_pathCity6_City7_City8_City9_Country_some_other_strings

City8 full_pathCity6_City7_City8_City9_Country_some_other_strings

City9 full_pathCity6_City7_City8_City9_Country_some_other_strings\

dirTOcombo.au3

Edited by vacko
Link to comment
Share on other sites

cant you use something like StringSplit on _Country?

$array = StringSplit('City6_City7_City8_City9_Country_some_other_strings\ ', '_Country', 1)
MsgBox(0,'',$array[1])

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

cant you use something like StringSplit on _Country?

$array = StringSplit('City6_City7_City8_City9_Country_some_other_strings ', '_Country', 1)
MsgBox(0,'',$array[1])

No, because delimiter is not "_Country" but just "_". Country and words behind it are not necessary.

Also, City6_City7_City8_City9 should be 4 separated records in 2D array, linked with (same) path.

Link to comment
Share on other sites

I modified this part of your code starting around line 57.

; convert 1D array into 2D (add short name into Col 0 and put original dir name into Col 1)
        Global $DirList2D[1][2]
        $j = 1
        For $A = 1 To $DirListTMP[0]
            $temp = StringLeft ($DirListTMP[$A], StringInStr($DirListTMP[$A], $constatnString)-1)
            $temp = StringSplit($temp, "_")
            _ArrayDelete($temp, UBound($temp))
            For $i = 1 To $temp[0] - 1 Step 1
                $DirList2D[$j - 1][0] = $temp[$i]
                $DirList2D[$j - 1][1] = $DirListTMP[$A]
                $j += 1
                ReDim $DirList2D[$j][2]
            Next
        Next
        _ArrayDelete($DirList2D, UBound($DirList2D)) ; gets rid of trailing space at end of array
Link to comment
Share on other sites

Along the line of what BogQ said...

If the string "_Country" is in each line, and not something like "_Canada" or "_Italy" then just change line 61 to:

$DirList2D[$A-1][0] = StringLeft ($DirListTMP[$A], StringInStr($DirListTMP[$A], "_Country")-1)

Link to comment
Share on other sites

I modified this part of your code starting around line 57.

; convert 1D array into 2D (add short name into Col 0 and put original dir name into Col 1)
Global $DirList2D[1][2]
$j = 1
For $A = 1 To $DirListTMP[0]
$temp = StringLeft ($DirListTMP[$A], StringInStr($DirListTMP[$A], $constatnString)-1)
$temp = StringSplit($temp, "_")
_ArrayDelete($temp, UBound($temp))
For $i = 1 To $temp[0] - 1 Step 1
$DirList2D[$j - 1][0] = $temp[$i]
$DirList2D[$j - 1][1] = $DirListTMP[$A]
$j += 1
ReDim $DirList2D[$j][2]
Next
Next
_ArrayDelete($DirList2D, UBound($DirList2D)) ; gets rid of trailing space at end of array

Seems to be OK, thanks a lot !
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...