用Powershell对文件批量重命名
来源:互联网 发布:tcp ip网络编程 代码 编辑:程序博客网 时间:2024/06/05 02:47
重命名示例
需求:將D盤For PS文件夾下的A.txt文件重命名爲aa.txt
rename-Item 'D:\For PS\A.txt' -NewName 'aa.txt'
批量改文件擴展名
需求:將D盤For PS文件夾下的所有的txt文件改爲html文件,即.txt改爲.html
get-childItem 'D:\For PS' *.txt | rename-item -newname { $_.name -replace '\.txt','.html' }
備註:由於replace的模式匹配字符串參數支持正則表達式,'.txt'要轉義成'\.txt'。
批量爲文件加前綴
需求:將D盤For PS文件夾下的所有的txt文件加上一個“Test_”的前綴
cd 'D:\For PS'get-childItem -r *.txt | rename-Item -newname{'Test_'+$_.name}
如果覺得上面的命令太精簡,看不太懂,可以用如下語句,更好理解些:
$dir = dir D:\ForPS *.txtforeach($_ in $dir){rename-Item $_.FullName -NewName ('Test_'+$_.Name)}
最後 一例
將D盤For PS文件夾下的所有的txt文件重命名為 Note1.txt、Note2.txt這樣的形式
get-childItem 'D:\For PS' -r *.txt | foreach-Object -Begin {$count = 1} -Process{ rename-Item $_.fullname -NewName "Note$count.txt";$count++}
用PowerShell以編程的思想去操作文件,還可以實現更多更複雜的需求。
0 0
- 用Powershell对文件批量重命名
- 利用matlab对文件批量重命名
- 对指定文件夹下的文件批量重命名
- 文件批量重命名
- 文件批量重命名
- 文件批量重命名
- 文件批量重命名
- 文件批量重命名
- 文件批量重命名
- 文件批量重命名
- 文件批量重命名
- 文件批量重命名
- 文件批量重命名
- 文件批量重命名的工具
- 文件批量重命名代码
- linux 文件批量重命名
- php文件批量重命名
- linux之文件批量重命名
- 通知
- 职场中各职位英文缩写
- VolleyLog-学习Google封装的Log
- UVA 11437 || Triangle Fun
- Java的抽象类和接口
- 用Powershell对文件批量重命名
- web页面树形下拉选择框
- [LeetCode] Intersection of Two Linked Lists
- 线段树模板
- split的简单使用
- 九度OJ题目1202:排序
- 《数据可视化实战:使用D3设计交互式图表 》笔记
- try catch 异常处理
- 层次遍历