10 Replies Latest reply on Jul 6, 2012 5:59 PM by Deepak Gupta

    Delete Specific Files from a folder

    Deepak Gupta

      I'm trying to write a macro which will delete specific files from a folder based on the value of custom property but could not get as what should be the codes for deleting the file.. Here are my codes


      Dim swApp           As SldWorks.SldWorks

      Dim swModel         As SldWorks.ModelDoc2

      Dim sFileName       As String

      Dim Path            As String

      Dim nErrors         As Long

      Dim nWarnings       As Long


      Sub main()


          Set swApp = Application.SldWorks   

          Path = "C:\SolidWorks\Test\"   

          sFileName = Dir(Path & "*.SLDPRT")      

          Do Until sFileName = ""


          Set swModel = swApp.OpenDoc6(Path + sFileName, swDocPART, swOpenDocOptions_Silent, "", nErrors, nWarnings)

          Set swModel = swApp.ActiveDoc


          If swModel.CustomInfo2("", "Description") = "XYZ" Then


      'What codes needs to be inserted here to delete the file.


          swApp.CloseDoc swModel.GetTitle

          Set swModel = Nothing

          sFileName = Dir




      End Sub