[英]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
,输入就不会关心哪种编码。
cd c:\\MyDirectoryWithCrazyCharacterEncodingAndUnicode
cd c:\\MyDirectoryWithCrazyCharacterEncodingAndUnicode
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.