# Define an array of paths to the folders you want to clear of files.
# Ensure you use full paths (e.g., 'C:\Temp\Folder1', 'D:\Data\Folder2')
$foldersToDeleteFrom = @(
"G:\VS Projects\Errors\",
"G:\VS Projects\Covers\",
"G:\VS Projects\Main\",
"G:\VS Projects\Temp\" # Add more paths as needed
)
# Use -Recurse if you also want to delete files in subfolders.
# Use -Force to delete hidden or read-only files.
# The "/*.*" pattern targets files with an extension, preventing folders from being deleted.
foreach ($folderPathin$foldersToDeleteFrom) {
if (Test-Path-LiteralPath$folderPath) {
try {
# Use Join-Path to add "*" so it targets the INSIDE of the folder
$contents = Join-Path-Path$folderPath-ChildPath"*"
# Use -Recurse to grab subfolders/files, but the wildcard keeps the root folder
Remove-Item-Path$contents-Recurse-Force-ErrorActionStopWrite-Host"Cleared contents of: $folderPath"-ForegroundColorGreen
}
catch {
Write-Host"Failed to clear ${folderPath}: $_"-ForegroundColorRed
}
}
}
Write-Host"Script finished."-ForegroundColorMagenta#====If you want to stop the process at the end, uncomment this next line.
#====This is used in case there is an error.
#Read-Host "Press Enter to exit"
Several options for running this.
Right-click and choose [run with PowerShell]
Run with [PowerShell ISE][li]Right-click the file and choose [Properties]
Click the [Change..] button
Scroll down and choose [Look for another app on this PC] Paste this in %windir%\system32\WindowsPowerShell\v1.0
Copy
Search Site
Search Google
Click [Enter].
Select [powershell_ise.exe ]and click [Open] (This is the PS Editor. Great for design and editing your Scripts)
Click [Apply] and [OK]
When you double-click the file, it will open the [ISE].