Created
February 18, 2022 21:51
-
-
Save airways/0a9c56c45064868a39249f229b513268 to your computer and use it in GitHub Desktop.
Remove non-ascii characters from filenames
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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