Skip to content

Instantly share code, notes, and snippets.

@airways
Created February 18, 2022 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save airways/0a9c56c45064868a39249f229b513268 to your computer and use it in GitHub Desktop.
Save airways/0a9c56c45064868a39249f229b513268 to your computer and use it in GitHub Desktop.
Remove non-ascii characters from filenames
# This will allow for the files to be zipped by the built-in Explorer "Compress to ZIP file" command
function FixFilenames {
pwd
$Files = gci
$Files | ForEach-Object {
$OldName = $_.Name
$NewName = $OldName -replace "[^\u0020-\u007F]", "_"
if ( $OldName -ne $NewName ) {
echo "$OldName -> $NewName"
ren $_ $NewName
}
if ((Get-Item $NewName) -is [System.IO.DirectoryInfo]) {
#echo ":Enter $NewName"
cd $NewName
FixFilenames
#echo ":Leave $NewName"
cd ..
}
}
}
echo ":Start"
FixFilenames
echo ":Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment