Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm going to take a SWAG at this: I think you want to create a string that combines the directory and sub-directory names with a space in between. </p> <p>Here is a script that assumes more than one subfolder in your current directory and uses <code>FileSystemObject</code> and <code>Folder</code> to create a name as you describe for each one (held in and accessible from an array). NOTE that you need to set a reference to Microsoft Scripting Runtime. I tested this with a file path to My Documents on my C: drive and it worked. Hope this helps:</p> <pre><code>Sub CreateStringsForSubfolders() 'To use this you need a reference set for Microsoft Scripting Runtime '~~&gt;dim variables and set initial values Dim fsObject As New FileSystemObject Dim fFolder As Folder Set fFolder = fsObject.GetFolder("\\Tardis\Data\[PATH]\HELLO") Dim fSubfolder As Folder Dim aNames() As String ReDim aNames(1) As String '~~&gt;loop to create name for each subfolder For Each fSubfolder In fFolder.SubFolders ReDim Preserve aNames(UBound(aNames) + 1) aNames(UBound(aNames)) = fFolder.Name &amp; " " &amp; fSubfolder.Name Debug.Print aNames(UBound(aNames)) 'press [CTRL + G] to see the names created Next End Sub </code></pre> <hr> <p>Here is a modified code with your requirement. I'm not really sure what you're doing with this (it might have helped if you had included that information in your question) so I assumed that you just wanted to add the sub folders to the array. If you actually wanted there always to be two folders' names in the string created, then use the commented alternative in the <code>Else</code> section.</p> <pre><code>Sub CreateStringsForSubfolders2() '~~&gt;dim variables and set initial values Dim sPath As String Dim fsObject As New FileSystemObject Dim fFolder As Folder Set fFolder = fsObject.GetFolder("\\Tardis\Data\[PATH]") Dim fSubfolder As Folder Dim fSubfolder2 As Folder Dim aNames() As String ReDim aNames(1) As String '~~&gt;loop to create name for each subfolder and any sub-subfolders For Each fSubfolder In fFolder.SubFolders ReDim Preserve aNames(UBound(aNames) + 1) sPath = fSubfolder.Path Set fSubfolder = fsObject.GetFolder(sPath) If fSubfolder.SubFolders.Count &lt;&gt; 0 Then For Each fSubfolder2 In fSubfolder.SubFolders ReDim Preserve aNames(UBound(aNames) + 1) aNames(UBound(aNames)) = fSubfolder.Name &amp; " " &amp; _ fSubfolder2.Name Debug.Print aNames(UBound(aNames)) Next fSubfolder2 Else aNames(UBound(aNames)) = fSubfolder.Name 'or fFolder.Name &amp; " " fSubfolder.Name Debug.Print aNames(UBound(aNames)) End If Next End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload