windows - 批量替换文件名中的字符

标签 windows powershell cmd file-rename batch-rename

我有大约 600 个标题中带有 $ 特殊字符的视频文件。

我想批量将其替换为字母s

我在下面在线找到了 powershell 代码,它可以很好地用其他字母替换字母,但在尝试替换 $ 特殊字符时失败

get-childitem -recurse | rename-item -newname { $_.name -replace "",""}

我尝试使用下面的代码,最终在文件类型的末尾添加了 s,而不是替换 $

get-childitem -recurse | rename-item -newname { $_.name -replace "$","s"}

$hortvid.mp4 变为 $hortvid.mp4s 而不是 shortvid。 mp4

关于如何让它正常工作有什么想法吗?

最佳答案

只需使用\转义字符:

在目录中运行行时:

get-childitem -recurse | rename-item -newname { $_.name -replace "\$","s"}

输入文件:

$hortvid.mp4

输出文件已重命名:

shortvid.mp4

关于windows - 批量替换文件名中的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65386307/

相关文章:

mysql - 通过批处理文件连接到 MySQL

CSS 在所有 Windows 浏览器中都能正常工作,但在 OSX 上的 Firefox 中却不行

c# - 一个 exe 中的多个 Windows 服务

c# - 无法加载 .ps1,因为在此系统上禁用了脚本的执行

powershell - 如何配置单个数据库和服务器的日志分析?

batch-file - 以编程方式仅删除 "%~dp0"返回的路径中的最后一个斜杠

powershell - 如何从 Notepad++ 执行 PowerShell 脚本

c - 将 2D 数组存储在 3D 数组中

c# - 如何以编程方式确定哪个应用程序正在锁定文件?

powershell - 为什么不能将字符串分配给强类型 bool 变量?