I have done a lot of work with Photoshop, where I end up having a ton of annoying TMP files after running a large batch action. This can take up unnecessary storage space and make it harder to sort through useful files.
Finding and deleting TMP files can be a huge pain. You can go to folder and search for all files by putting .TMP in the search box. However, there are reasons this may not work:
- You may have a very large set of files and the computer may not be able to search through all of them.
- You may have files in numerous folders that don’t even necessarily have the same parent folder.
- It may accidentally identify files that are not TMP files that have the letters TMP in the file name.
This means that it can be better to use a VBA macro. This macro will go through all of the folder paths shown in column A and delete every TMP file in them.
Sub DeleteTmpFiles()
Dim FolderPath As String
Dim FileName As String
Dim FileSystem As Object
Dim objFolder As Object
Dim objFile As Object
Dim LastRow As Long
Dim i As Long
' Create an instance of the FileSystemObject
Set FileSystem = CreateObject("Scripting.FileSystemObject")
' Find the last row with data in column A
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
' Loop through each cell in column A
For i = 1 To LastRow
' Get the folder path from column A
FolderPath = Cells(i, 1).Value
' Check if the folder path is valid
If FileSystem.FolderExists(FolderPath) Then
' Set objFolder to the folder path
Set objFolder = FileSystem.GetFolder(FolderPath)
' Loop through each file in the folder
For Each objFile In objFolder.Files
' Check if the file is a TMP file
If LCase(Right(objFile.Name, 4)) = ".tmp" Then
' Delete the TMP file
objFile.Delete
End If
Next objFile
Else
' Display a message if the folder path is invalid
MsgBox "Folder does not exist: " & FolderPath, vbExclamation
End If
Next i
' Clean up objects
Set FileSystem = Nothing
Set objFolder = Nothing
Set objFile = Nothing
' Display a message when the task is completed
MsgBox "TMP files deleted successfully!", vbInformation
End Sub
How Can This Macro Help Improve Your Computer’s Functionality?
Think of your computer as a room with lots of shelves and drawers. Over time, as you use your computer, it creates temporary files to help with different tasks, like running programs or saving data. These files are like sticky notes that your computer uses temporarily.
Now, imagine if you kept all those sticky notes after you’re done using them. Eventually, they’d pile up and clutter your room, making it harder to find what you need and slowing you down.
That’s where the VBA macro comes in. It’s like a smart organizer for your computer. It goes through all the folders, just like tidying up all the shelves and drawers in your room, and finds these temporary files. Then, it helps clean them up, like throwing away the sticky notes you don’t need anymore.
By getting rid of these temporary files, your computer runs smoother and faster, just like having a clean and organized room makes it easier to find things and move around. Plus, it frees up space on your computer for things that really matter, like your favorite apps and files. So, it’s like giving your computer a little spring cleaning to keep it running at its best!