DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Select multiple folders and store in array: type changes from folder object to string?

Solved!
Go to solution

Hi,

 

I am trying to implement the following:

 

The user selects a folder (which contains subfolders) in a dialog:

 

Set Dateiauswahl = CreateObject("Shell.Application").BrowseForFolder(0,"Verzeichnis auswählen",512,mess_path)

Set Ordner = CreateObject("Scripting.FileSystemObject").GetFolder(Dateiauswahl.Self.Path)

 

All subfolders in the selected folders are listed in two global array variables:

 

Call GlobalDim("FolderList("&Ordner.SubFolders.Count - 1&")")

Call GlobalDim("FolderPaths("&Ordner.SubFolders.Count - 1&")")
     

f=0
for each Unterordner in Ordner.SubFolders
    FolderList(f) = Unterordner.Name
    FolderPaths(f) = Unterordner
    f=f+1

next

 

Later on, only the files from some of the subfolders should be stored in another array FileList:

 

f=0
    for q=0 to UBound(auswahl)
       Unterordner = FolderPaths(auswahl(q))
       Call MsgBox(Unterordner)
       For Each File In Unterordner.Files
           if instr(1,File.Name,"Speed")=0 then
               FileList(f)= File.Path
               f=f+1
           end if
       Next

next

 

Now I seem to have a problem with the type of the data that is stored in the FolderPaths array. While Unterordner is a Folder Object, and needs to be a Folder Object for For Each File In Unterordner.Files to work, storing it in the array turns it into a string variable.

I don't really understand why, and am looking for a solution so that I can extract single subfolders from the FolderPaths array and then extract their files.

0 Kudos
Message 1 of 3
(4,763 Views)
Solution
Accepted by maliya

Hi maliya,

 

In order to assign an object to an array element (or any other variable), you must use the Set syntax, like this:

 

Set FolderPaths(f) = Unterordner

 

Then later on you can retrieve it with the same syntax:

 

Set Unterordner = FolderPaths(auswahl(q))

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 2 of 3
(4,739 Views)

what i found out is, that the order of the folders sometimes is mess - and i don´t know exactly why or on what the order depents.

it can be that your list is

 

c:\tmp\2

c:\tmp\1

c:\tmp\6

c:\tmp\3

 

to get the list in the right order i use a "bubble-sort"........

 

bubbleSort(Array A)
  for (n=A.size; n>1; n=n-1){
    for (i=0; i<n-1; i=i+1){
      if (A[i] > A[i+1]){ A.swap(i, i+1)
      } // ende if
    } // ende innere for-Schleife
  } // ende äußere for-Schleife

0 Kudos
Message 3 of 3
(4,686 Views)