powershell - 递归替换win10文件夹和文件中的非标准字符
问题描述
我有许多文件夹,其中包含从同事那里获得的具有特殊甚至隐藏字符的文件的子文件夹,例如:
非标准字符:{µ, 市, ', &, 「, 隐形字符, Ü, é, ... }
我正在寻找一个脚本或 Windows 工具,它可以通过根据列表 X 中的字符将任何非标准字符替换为标准字符来一次性重命名所有子文件夹和文件。奖励:如果该工具会更好将检查列表 R,并使用替换规则(如果已定义)。如果不是,它应该只用“_”替换非标准字符。
List X: {A-Z, a-z, 0-9, (, ), [,],-, _}
List R: {é->e , ü->u, ä->a, @->at,...} (Replacement rules)
感谢对工具或脚本的任何提示。
解决方案
这个怎么样?替换特定字符,然后替换空格和波浪号或制表符之间的任何内容,例如 unicode 雪人。
echo hi | set-content filä.txt,filé.txt,fil☃.txt # in script or ise
$pairs = ('ä','a'), ('é','e'), ('[^ -~\t]','_')
dir -r | where name -match '[^ -~\t]' | rename-item -newname {
$name = $_.name
foreach ($pair in $pairs) {
$name = $name -replace $pair
}
$name
} -whatif
What if: Performing the operation "Rename File" on target "Item:
C:\users\admin\foo\filä.txt Destination: C:\users\admin\foo\fila.txt".
What if: Performing the operation "Rename File" on target "Item:
C:\users\admin\foo\filé.txt Destination: C:\users\admin\foo\file.txt".
What if: Performing the operation "Rename File" on target "Item:
C:\users\admin\foo\fil☃.txt Destination: C:\users\admin\foo\fil_.txt".
推荐阅读
- css - CSS - 视频不完全适合其容器
- opengl - OpenGL - 使用 g++ 链接 glew 和 glut 库和 dll
- javascript - 为什么当我尝试访问特定值时我的 JSON 数组响应返回未定义
- c++ - 为什么c++空类没有字节对齐?
- android-studio - 带有android studio的新flutter应用程序无法在android模拟器上运行-出现异常:线程“main”javax.net.ssl.SSLHandshakeException中的异常:
- java - JPanel 透明背景和显示元素
- sql - 需要在 WHERE 子句中满足两个条件的 SQL
- r - R中的天气数据操作
- android - 如何使用从片段创建的观察者来切换带有来自 ViewModel 的消息的快餐栏
- numpy - 应用 np.apply_along_axis 用标签替换索引