Solved

VB script to loop through folders

Posted on 2012-04-12
3
322 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

724 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