Solved

VB script to loop through folders

Posted on 2012-04-12
3
320 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
ID: 37836747
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
ID: 37836750
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
ID: 37837196
Thanks for super quick response!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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