This VBScript is designed to count and delete garbage files from a directory and its subdirectories. Garbage files are defined as those with ".tmp" or ".bak" extensions.
Download the Script: Download the
cleanup.vbsscript file to your system.Run the Script:
- Open a command prompt (cmd) as an administrator.
- Navigate to the location where you saved the
index.vbsfile. - Run the script using the command
cscript index.vbs.
' Count garbage filesCountGarbageFilesobjFSO.GetSpecialFolder(0)' 0 represents the Desktop folderThis function counts the garbage files in the directory and its subdirectories.
' Call the function to search and delete garbage filesSearchAndDeleteGarbageFilesobjFSO.GetSpecialFolder(0)' 0 represents the Desktop folderThis function searches for and deletes garbage files from the directory and its subdirectories.
FunctionIsGarbageFile(objFile)Dimextensionextension=LCase(objFSO.GetExtensionName(objFile.Path))IsGarbageFile=(extension="tmp"Orextension="bak")EndFunctionThis auxiliary function determines if a file is garbage based on its extension.
You can customize this script by modifying the following parts:
- The file extensions considered as garbage (
tmpandbak) in the IsGarbageFile function. - The actions performed on the garbage files found in the
SearchAndDeleteGarbageFilesfunction, such as deletion or logging.
- Make sure to run the script as an administrator to avoid permission issues when deleting files.
- Basic error handling is provided to handle potential permission or access denied issues.
Thank you very much for helping in the project ❤