📊 VBA (Excel)
List Files in The system-wide Windows Temp folder (VBA)
Lists every file in the system-wide Windows Temp folder with size and last-modified date directly on the active worksheet, using Scripting.FileSystemObject.
WindowsTempListFiles.bas
Attribute VB_Name = "WindowsTempListFiles"
Option Explicit
Public Sub WindowsTempListFiles()
Dim fso As Object
Dim folder As Object
Dim f As Object
Dim folderPath As String
Dim ws As Worksheet
Dim r As Long
folderPath = "C:\Windows\Temp"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(folderPath) Then
MsgBox "Folder not found:" & vbCrLf & folderPath, vbExclamation
Exit Sub
End If
Set ws = ActiveSheet
ws.Cells.Clear
ws.Cells(1, 1).Value = "File Name"
ws.Cells(1, 2).Value = "Size (KB)"
ws.Cells(1, 3).Value = "Last Modified"
ws.Rows(1).Font.Bold = True
Set folder = fso.GetFolder(folderPath)
r = 2
For Each f In folder.Files
ws.Cells(r, 1).Value = f.Name
ws.Cells(r, 2).Value = Format(f.Size / 1024, "#,##0.0")
ws.Cells(r, 3).Value = f.DateLastModified
r = r + 1
Next f
ws.Columns.AutoFit
MsgBox (r - 2) & " file(s) listed from " & folderPath, vbInformation
End Sub