Set objArgs = Wscript.Arguments
Set objFso = createobject("scripting.filesystemobject")
set oShell = CreateObject("Shell.Application")
strFile_Path = "C:\temp\Cleanup.bat"
accoreconsole = "C:\Program Files\Autodesk\AutoCAD 2021\accoreconsole.exe" 'Put your current autocad path here
scriptFile = "x:\Lisp\BatchCleanup\BatchCleanup.scr" 'Put path to script file here
dim filesys, newfolder
set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists("C:\Temp\") Then
newfolder = filesys.CreateFolder ("C:\Temp\")
End If
Set filesys = CreateObject("Scripting.FileSystemObject")
filesys.CreateTextFile("C:\temp\Cleanup.bat"), True
If filesys.FileExists("C:\temp\Cleanup.bat") Then
filesys.DeleteFile "C:\temp\Cleanup.bat"
End If
'iterate through all the arguments passed
For i = 0 to objArgs.count
on error resume next
'try and treat the argument like a folder
Set folder = objFso.GetFolder(objArgs(i))
'if we get an error, we know it is a file
If err.number <> 0 then
'this is not a folder, treat as file
ProcessFile(objArgs(i))
Else
'No error? This is a folder, process accordingly
For Each file In folder.Files
ProcessFile(file.path)
Next
End if
On Error Goto 0
Next
Function ProcessFile(sFilePath)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(strFile_Path, ForAppending, True)
f.write "@echo off" & vbCrLf
f.write "Title Please wait while I clean up here..." & vbCrLf
if UCASE(Mid(sFilePath,len(sFilePath)-3,4)) = ".DWG" then
f.write "@echo [" & i+1 & "/" & objArgs.count & "]: Processing... " & sFilePath & vbCrLf
f.write Chr(34) & accoreconsole & Chr(34) & " /i " & Chr(34) & sFilePath & Chr(34) & " /s " & Chr(34) & scriptFile & Chr(34) & " " & ">C:\temp\cleanup.log" & vbCrLf
f.Close
Else
f.write "@echo off" & vbCrLf
f.write "@echo [" & i+1 & "/" & objArgs.count & "]: Skipping... " & sFilePath & vbCrLf
f.Close
End If
End Function
Dim shell
Set shell = CreateObject("WScript.Shell")
shell.Run strFile_Path