API retreive all doc including in sub-folder?

Discussion in 'SolidWorks' started by Sam, Aug 18, 2006.

  1. Sam

    Sam Guest

    I have a macro that will perform some particular operations on all
    the documents in a selected folder but I would also like for it to
    perform those same operations on all documents in all the sub-folders
    of the selected parent folder. Can someone please explain to me how to
    do this in vb?

    Thanks
     
    Sam, Aug 18, 2006
    #1
  2. Sam

    Tim Markoski Guest

    Here's a VB Script that shows how.


    Call Main

    Sub Main

    Dim objBrowse
    Dim objFSO
    Dim objFolder
    Dim objFolders
    Dim objFiles
    Dim objFile

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objBrowse = CreateObject("CCRPBrowseDlgSvr6.BrowseDialog")

    objBrowse.RootFolder = objBrowse.GetSpecialFolderName(&H11)
    objBrowse.BrowseMode = bdBrowseAllFolders

    If objBrowse.Browse = True Then

    If objFSO.FolderExists(objBrowse.SelectedFolder) = True Then

    Set objFolder = objFSO.GetFolder(objBrowse.SelectedFolder)
    Set objFolders = objFolder.SubFolders
    Set objFiles = objFolder.Files

    If objFiles.Count = 0 Then

    MsgBox "No files present is selected folder!", vbExclamation,
    "Scripting Object Model"

    End If

    For Each objFile In objFiles

    MsgBox "File Name: " & objFile.Path, vbInformation, "Scripting
    Object Model"

    Next

    For Each Folder In objFolders

    Set objFiles = Folder.Files
    If objFiles.Count = 0 Then

    MsgBox "No files present is selected folder!", vbExclamation,
    "Scripting Object Model"

    End If

    For Each objFile In objFiles

    MsgBox "File Name: " & objFile.Path, vbInformation,
    "Scripting Object Model"

    Next

    next

    Else

    MsgBox "No Folder Selected", vbExclamation, "Scripting Object Model"

    End If

    End If

    ' Explicit Cleanup
    Set objFolders = Nothing
    Set objFolder = Nothing
    Set objFiles = Nothing
    Set objFSO = Nothing
    Set objBrowse = Nothing

    End Sub
     
    Tim Markoski, Aug 19, 2006
    #2
  3. Sam

    TOP Guest

    TOP, Aug 19, 2006
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.