简体   繁体   English

在Windows中,如何在某个目录中找到所有使用unicode编码的文件?

[英]In Windows, how do I find all files in a certain directory that are encoded using unicode?

I am having trouble searching a large directory of files for a string. 我在大型文件目录中搜索字符串时遇到麻烦。 The search command I'm using is skipping any file encoded in Unicode. 我正在使用的搜索命令正在跳过任何以Unicode编码的文件。 I want to find all the files in this directory that are encoded in Unicode. 我想找到此目录中所有以Unicode编码的文件。 I am on Windows XP. 我在Windows XP上。

Thank you! 谢谢!

You don't know encoding before you open a file and read from it. 打开文件并读取文件之前,您不了解编码。 So you will enumerate directory files, then go through the list, open and check either BOM or the content itself (such as certain amount of heading bytes). 因此,您将枚举目录文件,然后遍历列表,打开并检查BOM或内容本身(例如一定数量的标题字节)。

You can do it with my script below, the input does not care what encoding, as far as you specify the output encoding like this -Encoding ASCII . 您可以在下面的脚本中执行此操作,只要指定输出编码(如-Encoding ASCII ,输入就不会关心哪种编码。

  1. Goto the Dir you want cd c:\\MyDirectoryWithCrazyCharacterEncodingAndUnicode 转到您想要的目录cd c:\\MyDirectoryWithCrazyCharacterEncodingAndUnicode
  2. Fire this script away! 将此脚本解开!

Copy and past the script in your Powershell windows, you get the idea just play with it to fix the syntax 将脚本复制并粘贴到Powershell窗口中后,您会发现仅使用脚本来修复语法

 foreach($FileNameInUnicodeOrWhatever in get-childitem )
 {        
    $tempEncoding = (Get-Content -encoding byte)
    write-output $FileNameInUnicodeOrWhatever "has encoding" $tempEncoding   

    //  [System.Text.Encoding]::$result
 }

If you want to further resolve issues with not being able to find files because of encoding, change the encoding type 如果要进一步解决由于编码而无法找到文件的问题,请更改编码类型

The find command in Windows supports Unicode text files. Windows中的find命令支持Unicode文本文件。 findstr doesn't. findstr没有。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用CMD / Powershell查找目录(包括子目录)中的所有文件,然后显示具有某些扩展名的文件 - How to, using CMD/Powershell, find all files in a directory (including subdirectories), and then display files that have certain extensions 如何使用Windows命令行找到所有exe文件? - how do I find all exe files using command line for windows? 如何使用Windows批处理文件删除不包含某些字符的文件? - How can I Delete Files That Do Not Contain Certain Characters Using Windows Batch File? 如何使用Windows通配符查找目录中的所有文件名 - How to find all file names in a directory using windows wildcards 如何使用C ++列出Windows目录中的所有CSV文件? - How to list all CSV files in a Windows Directory using C++? 如何使用C#查找Windows服务的安装目录? - How do I find the install directory of a Windows Service, using C#? 如何使用Windows批处理文件在其中找到目录并将其存储到变量中? - How do I find a directory in and store it into a variable, using a Windows batch file? 如何复制目录结构但只包含某些文件(使用 Windows 批处理文件) - How to copy a directory structure but only include certain files (using windows batch files) 在批处理文件中,如何删除非特定类型的所有文件 - In a batch file, how do I delete all files NOT of a certain type 如何获取目录中具有特定扩展名的所有文件? - How do I get all the files with a particular extension inside a directory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM