How to bulk convert unicode file names to Ascii file names windows CMD or powershell

前端 未结 1 1527
太阳男子
太阳男子 2021-01-07 15:38

Problem: For some odd reason, the windows zip util will not zip up folders with Unicode file names. So, I need to convert a large set of filenames

相关标签:
1条回答
  • 2021-01-07 16:16

    It took me a while, since I am not a powershell guy clearly... but it worked, and I am sharing!!

    1. Goto the Dir you want cd c:\MyDirectoryWithCrazyCharacterEncodingAndUnicode
    2. Fire this script away!

    Copy and past the script in your Powershell windows

         foreach($FileNameInUnicodeOrWhatever in get-childitem)
         {
            $FileName = $FileNameInUnicodeOrWhatever.Name    
            $TempFile = "$($FileNameInUnicodeOrWhatever.Name).ASCII"    
            get-content $FileNameInUnicodeOrWhatever | out-file $TempFile -Encoding ASCII     
            remove-item $FileNameInUnicodeOrWhatever    
            rename-item $TempFile $FileNameInUnicodeOrWhatever
            # only if you want to debug
            # write-output $FileNameInUnicodeOrWhatever "converted to ASCII ->" $TempFile
        }
    

    While searching I also found out how to fix the encoding for others, for people who keep getting output encoding to ASCII or Unicode all the time, you can set output encoding to whatever encoding you want from Microsoft blog $OutputEncoding

    Issues 1, 2, 3 for bulk Hex to Ascii just replace the file names with variable you want to input

    0 讨论(0)
提交回复
热议问题