使用Powershell查找字符并重命名文件名 [英] Find characters and rename file name using Powershell

查看:248
本文介绍了使用Powershell查找字符并重命名文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在目录中有许多文件使用这种命名约定:"1050_14447_Letter Extension.pdf",等等.我需要删除第二个下划线(包括第二个下划线)之前的所有字符.因此,新文件名为"Letter Extension.pdf".我该如何迭代单个目录的重命名?

I have a large number of files in a directory with this type of naming convention: "1050_14447_Letter Extension.pdf", etc. I need to remove all characters before the 2nd underscore (including the 2nd underscore). So the new file name would be "Letter Extension.pdf". How can I iterate the single directory renaming accordingly?

推荐答案

以下是重命名当前目录中所有pdf文件的示例,该文件名中删除了所有前导数字或下划线:

Here's an example to rename all pdf files in the current directory, removing all leading numbers or underscores from the file name:

Get-ChildItem -Filter *.pdf | Rename-Item -NewName {$_.Name -replace '^[0-9_]+'}

这篇关于使用Powershell查找字符并重命名文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆