在cmd中搜索并替换名字

Search and replace name in cmd

我真的需要你的帮助我在我的硬盘驱动器中感染了病毒 Win32/Delf.NRJ 将字母“g”添加到文件名的开头并隐藏文件并将属性更改为系统所以我需要 运行 attrib -s -r -a -h /D /S 来取消隐藏它。

如果我可以 运行 在所有驱动器和每个以“g”开头并隐藏的 exe 文件上使用 cmd 或 powershell 进行一些搜索,删除属性并删除“g”并取消隐藏它?

我在这个驱动器中有很多 exe,要遍历所有文件(完整 2TB)

谢谢

您可以使用 Get-ChildItem -Attributes Hidden,System 来发现设置了 System 属性的隐藏文件:

$affectedExecutables = Get-ChildItem -Attributes Hidden,System -Filter g*.exe -Recurse

您可以将 -replace 正则表达式运算符与 Rename-Item 一起使用,以从名称中删除 g,如下所示:

$renamedExecutables = $affectedExecutables |Rename-Item -NewName { $_.Name -replace '^g' } -PassThru

最后,PowerShell 允许您直接修改文件属性:

$systemHiddenAttributes = [System.IO.FileAttributes]'Hidden,System'
$renamedExecutables |ForEach-Object {
  $_.Attributes = $_.Attributes -bxor $systemHiddenAttributes
}

这将从文件中删除隐藏和系统属性