/build/static/layout/Breadcrumb_cap_w.png

Deleting temporary files

I intend writing a script to delete temporary files on the system.
I know the FileSystemObject in VBScript/WSH can do this but I need to add some intelligence whereby if the file can't be deleted the script should skip the file and move to the next one.

One problem I do envisage is the fact the FileSystemObject isn't that intelligent to accomplish the task.

I could have put my trust in WMI using e.g. available from Technet and ScriptCentre but files starting with ~*** may fail when one tries to delete them especially when the original file is open.

Does anyone have any suggestions/ideas or knows of any tool in the market which does the aforementioned?

0 Comments   [ + ] Show comments

Answers (5)

Posted by: WiseUser 19 years ago
Fourth Degree Brown Belt
0
The FileSystem object may fall over at the first sign of trouble if you use wilcards.

But, if you write your own loop (to enumerate all files in the folder/subfolders) it should work perfectly.
Posted by: kkaminsk 19 years ago
9th Degree Black Belt
0
I think that is something to definately keep in mind when trying to do wildcard type filesystem actions in VBScript. It takes more code than you think to get things done right. I am working on a script to enumerate files, check them with a destination, copy them if version is newer and then have all the error handling for everything that can go wrong. Let's just say it went from simple script to a significant undertaking.
Posted by: WiseUser 19 years ago
Fourth Degree Brown Belt
0
Here's a quick untested modification of a script I posted here a few days ago. Might be of use?


Set oFso = CreateObject("Scripting.FileSystemObject")

DeleteFiles ".tmp", "C:\Windows\Temp", True

Sub DeleteFiles(sSearch, sFolder, bRecurse)

Set oFolder = oFso.GetFolder(sFolder)

Set cFiles = oFolder.Files

For Each oFile in cFiles

If Instr(LCase(oFile.Name),LCase(sSearch)) <> 0 Then

oFso.DeleteFile oFile.Path, True

End If

Next

Set cSubFolders = oFolder.SubFolders

If bRecurse Then

For Each oSub in cSubFolders

DeleteFiles sSearch, oSub.Path, bRecurse

Next

End If

End Sub

Set oFso = Nothing
Posted by: oofemioo 18 years ago
Blue Belt
0
2nd line of the script deletes files with .tmp extension.
How would one search for files that have ~ (tildas) anywhere in the name of the files as such files are the main files requiring deletion.
Posted by: WiseUser 18 years ago
Fourth Degree Brown Belt
0
It should simply be a case of changing the second line?

DeleteFiles "~", "C:\Windows\Temp", True

I haven't tried it, but it should work.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ