Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

VB script to loop through folders

I have this code which returns the properties of files in a directory, does anyone know how to amend this to read files in sub directories?

Sub main()

Dim swApp As Object
Sub main()
Dim Part As SldWorks.ModelDoc2
Dim PartNumber As String
    Set swApp = Application.SldWorks

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile("C:\File.csv", True)

    FileName = Dir("C:\Temp\*.SLDPRT")
    Visibility = swApp.DocumentVisible(False, swDocPART)
    a.writeline ("Part Number" & "," & "Description")

    Do While FileName <> ""
        Set Part = swApp.OpenDoc("C:\Temp\" & FileName, swDocPART)
        Description = Part.GetCustomInfoValue("", "DESCRIPTION")
        PartNumber = Part.GetCustomInfoValue("", "Part_No.")
        a.writeline (PartNumber & "," & Description)
        swApp.CloseDoc FileName
        FileName = Dir
    Loop

    Visibility = swApp.DocumentVisible(True, swDocPART)

End Sub
0
HKFuey
Asked:
HKFuey
  • 2
1 Solution
 
AnuroopsunddCommented:
Option Explicit
Dim strFolderToSearch, objFSO, objRootFolder, objFolder, colSubfolders, strOutput

strFolderToSearch = "C:\Windows\"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objRootFolder = objFSO.GetFolder(strFolderToSearch)
Set colSubfolders = objRootFolder.SubFolders

For Each objFolder in colSubfolders
     strOutput = strOutput & objFolder.name
     strOutput = strOutput &  vbCrLf
Next

MsgBox strOutput
0
 
AnuroopsunddCommented:
your code should go in between for loop...


For Each objFolder in colSubfolders
     strOutput = strOutput & objFolder.name
     strOutput = strOutput &  vbCrLf
Next
0
 
HKFueyAuthor Commented:
Thanks for super quick response!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now