Skip to content

Instantly share code, notes, and snippets.

@jaboc83
Created June 24, 2015 15:17
Show Gist options
  • Save jaboc83/1522b42fc2d643b37585 to your computer and use it in GitHub Desktop.
Save jaboc83/1522b42fc2d643b37585 to your computer and use it in GitHub Desktop.
Delete Long File Names in Windows
[CmdletBinding()]
param (
[Parameter(Mandatory=$True, Position=1)]
$Filter
)
$batFileContent = @"
mkdir a
robocopy a %1 /s /mir
rmdir a
rmdir %1
"@
$batFileName = "long.bat"
if (-not (Test-Path $batFileName)) {
$batFileContent | Out-File $batFileName -Encoding ascii
}
Get-ChildItem $Filter | ForEach { ./long.bat $_.FullName | Write-Output }
if (Test-Path $batFileName) {
Remove-Item $batFileName
}
@jaboc83
Copy link
Author

jaboc83 commented Jun 24, 2015

This is a simple script for deleting files with names too long for windows to normally delete. My buildserver has folders in the format 100.tcbuildid, 101.tcbuildid, 102.tcbuildid, etc.... so I can easily clean the bad files out using this command like so:

./longKill.ps1 10*.tcbuildid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment