EMP*_*EMP 13 filesystems unicode file-search windows-xp
有没有什么简单的方法可以在特定目录中查找文件名中包含任何非 ASCII(即 Unicode)字符的所有文件?我正在运行 Windows XP x64 SP2、NTFS 文件系统。
Che*_*vel 17
这是使用Powershell的方法:
gci -recurse . | where {$_.Name -cmatch "[^\u0000-\u007F]"}
Run Code Online (Sandbox Code Playgroud)
我最终为此编写了一个 Python 脚本。发布它以防它对任何人有帮助。随意移动到 StackOverflow。
import sys, os
def main(argv):
if len(argv) != 2:
raise Exception('Syntax: FindUnicodeFiles.py <directory>')
startdir = argv[1]
if not os.path.isdir(startdir):
raise Exception('"%s" is not a directory' % startdir)
for r in recurse_breadth_first(startdir, is_unicode_filename):
print(r)
def recurse_breadth_first(dirpath, test_func):
namesandpaths = [(f, os.path.join(dirpath, f)) for f in os.listdir(dirpath)]
for (name, path) in namesandpaths:
if test_func(name):
yield path
for (_, path) in namesandpaths:
if os.path.isdir(path):
for r in recurse_breadth_first(path, test_func):
yield r
def is_unicode_filename(filename):
return any(ord(c) >= 0x7F for c in filename)
if __name__ == '__main__':
main(sys.argv)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11201 次 |
最近记录: |