Solved

VB script to loop through folders

Posted on 2012-04-12
3
314 Views
Last Modified: 2012-08-14
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
Comment
Question by:HKFuey
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
Anuroopsundd earned 500 total points
Comment Utility
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
 
LVL 17

Expert Comment

by:Anuroopsundd
Comment Utility
your code should go in between for loop...


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

Author Closing Comment

by:HKFuey
Comment Utility
Thanks for super quick response!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now