-1

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 (not the contents) to ASCII files names. The answers here discuss content conversion

Cannot compress files with UNICODE names

How do I mass/bulk convert/rename the file name itself in windows CMD line or Power Shell. I don't care about what the outputfile name has extra1 etc.

//While this changes the content inside the file. it does not rename my file name!

  COPY /Y UniHeader.txt Unicode_Output.txt
  CMD /U /C Type ANSI_Input.txt >> Unicode_Output.txt
Community
  • 1
  • 1
Transformer
  • 3,100
  • 17
  • 40
  • Your *best* choice is going to be to find a third-party compression utility that handles Unicode file names. Writing code to rename the files, while not too difficult, is still more trouble than it is worth - particularly since it will leave you with an archive that is of relatively little use, because the file names bear no relationship to their contents. – Harry Johnston Jan 27 '17 at 05:25
  • ok thanks I am trying 7zip with better luck, but it also crashes. the names of the files dont matter, because they're going to be served up as guids anyway. – Transformer Jan 27 '17 at 05:47
  • Unicode - Ascii conversion is highly untrivial a task. You might have some luck with [removing the diacritics](http://stackoverflow.com/questions/249087/how-do-i-remove-diacritics-accents-from-a-string-in-net), but this error prone. Morale: never, ever, use non-ASCII characters in file names. (My mother tongue has diacritics, so I've been dealing with such a probelms since the 80's...) – vonPryz Jan 27 '17 at 07:47
  • @vonPryz that was funny :) but I got it resolved finally, yay! – Transformer Jan 27 '17 at 07:56

1 Answers1

0

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

Community
  • 1
  • 1
Transformer
  • 3,100
  • 17
  • 40