如何将Unicode文件名批量转换为Windows CMD或Powershell的Ascii文件名 [英] How to bulk convert unicode file names to Ascii file names windows CMD or powershell

查看:191
本文介绍了如何将Unicode文件名批量转换为Windows CMD或Powershell的Ascii文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:出于某些奇怪的原因, windows zip util不会使用Unicode文件名将 up 文件夹压缩。因此,我需要将大量的文件名(而不是内容)转换为ASCII文件名。答案



如何在Windows中批量转换/重命名文件名本身CMD行或Power Shell。我不在乎输出文件名中是否包含extra1等。

  //虽然这会更改文件内的内容。它不会重命名我的文件名! 

COPY / Y UniHeader.txt Unicode_Output.txt
CMD / U / C类型ANSI_Input.txt>> Unicode_Output.txt


解决方案

我花了一段时间,显然不是一个强力的家伙...但是它确实有效,并且我正在共享 !!


  1. 转到您要的目录 cd c:\ DirectMyDirectoryWithCrazyCharacterEncodingAndUnicode

  2. 解开此脚本!

在Powershell窗口中复制并粘贴脚本

  foreach($ FileNameInUnicodeOrWhatever in get-childitem)
{
$ FileName = $ FileNameInUnicodeOrWhatever.Name
$ TempFile = $($ FileNameInUnicodeOrWhatever.Name).ASCII
get-content $ FileNameInUnicodeOrWhatever |输出文件$ TempFile-编码ASCII
remove-item $ FileNameInUnicodeOrWhatever
重命名项目$ TempFile $ FileNameInUnicodeOrWhatever
#仅当您要调试
#写入输出$ FileNameInUnicodeOrWhatever转换为ASCII-> $ TempFile
}

在搜索的同时,我还发现了如何为其他人修复编码,适用于始终保持输出编码为ASCII或Unicode 的人,您可以设置输出编码为您想要的任何编码来自Microsoft博客 $ OutputEncoding



问题 1 2 3对于将十六进制批量转换为Ascii,只需将文件名替换为变量y您想输入


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

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

解决方案

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

这篇关于如何将Unicode文件名批量转换为Windows CMD或Powershell的Ascii文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆