AnsweredAssumed Answered

How can I make deleting folders faster in Windows 10

Question asked by Peter Cranshaw on Jun 25, 2018
Latest reply on Jun 25, 2018 by Peter Cranshaw

I'm writing a program (macro) to package drawings in my company into .ZIP files that include all the file formats that our different vendors need to work with them. To do that, it creates a temp folder and then use the "pack and go" functions in the soldiworks api to copy the files to that folder.  With that it loops through the files and generates the different formats as needed.  Once done it compress the contents of the tempfolder to a .ZIp file.


I've gotten the macro working pretty well.  It cycles through all the files very neatly and generates the .ZIP file in short order.


The only problem that I have left is cleaning up afterwards.  I need to get rid of the temp folder I made. On my own machine it happens reasonably fast. The tempfolder for a small assembly will take about 5 seconds to be deleted.  But on other machines around my office that same folder will take as long as 2 minutes!


The one pattern I've noticed is that the fast machines are running Windows 7 and the slow machines are running Windows 10.


I've tried several different methods to remedy this, but the results have all been the same...



' Delete the "tempfolder"                                              '


Sub DeleteTempFolder()


    Dim fso As Object

    ' Get the basic Windows Filesystem objects

    Set fso = CreateObject("Scripting.FileSystemObject")

    fso.DeleteFolder (tempfolder)


     ' Using VBA

'    Kill tempfolder & "\*"

'    RmDir tempfolder


    ' Using the Wscript.Shell

'    Dim WshShell As Object

'    Dim waitOnReturn As Boolean: waitOnReturn = True

'    Dim windowStyle As Integer: windowStyle = 0

'    Set WshShell = CreateObject("WScript.Shell")

    ' Run the command

'    WshShell.Run "del " & Chr(34) & tempfolder & "\*" & Chr(34) & " /Q", windowStyle, waitOnReturn

'    WshShell.Run "rmdir " & Chr(34) & tempfolder & "\" & Chr(34) & " /Q", windowStyle, waitOnReturn


End Sub


Does anyone have any suggestions how I can make removing that tempfolder faster on Windows 10?