替换“."用“_"在文件名中 [英] Replace "." with "_" in file name
本文介绍了替换“."用“_"在文件名中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 PowerShell 替换 pdf 文件名:
I am using PowerShell to replace pdf file names:
Get-ChildItem -Path C:\All -Filter *.pdf | Rename-Item -NewName { $_.Name.Replace('.','_') }
如果我将 %20
替换为 _
效果很好,但是如果我们使用test.one.pdf",我需要test_one.pdf"作为输出,如果我使用上述语法,它会替换 .在 pdf 之前,如test_one_pdf".
It works fine if I replace %20
to _
, but if we use "test.one.pdf", I need "test_one.pdf" as output, if I use above syntax it replaces the . before pdf like "test_one_pdf".
推荐答案
你的代码会将 name.001.pdf
重命名为 name_001_pdf
,所以除非你真的想删除您只需要在文件名中替换文件的扩展名,而不是扩展名.
Your code will rename name.001.pdf
to name_001_pdf
, so unless you actually want to remove the extensions of your files you need to replace only within the files name and not the extension.
Get-ChildItem -Path "C:\All" -Filter "*.pdf" | Rename-Item -NewName { $_.BaseName.Replace(".","_") + $_.Extension }
这篇关于替换“."用“_"在文件名中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文