Powershell-通过“文件名"查找文件并基于CSV重命名 [英] Powershell - find file by 'file name' and rename based on CSV

查看:103
本文介绍了Powershell-通过“文件名"查找文件并基于CSV重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows目录中有一组文件(旧名称),我想根据以下CSV文件重命名(新名称):

I have a set of files (OldName) in a Windows directory that I would like to rename (NewName) based on the following CSV file:

OldName,NewName
Sources/texas play_PGC_Cpgc_entryPoint_Cbp_1.f4v,01 Texas Play.f4v
Sources/texas play_PGC_Cpgc_entryPoint_Dbp_1.f4v,02 First Song.f4v
Sources/texas play_PGC_Cpgc_entryPoint_Ebp_1.f4v,03 Yellow Rose.f4v

我不确定如何循环遍历CSV文件...查找每个文件并进行替换.

I'm not sure how to loop thru the CSV file... finding each file and replacing.

任何想法都将不胜感激.

Any thoughts would be appreciated.

推荐答案

首先将CSV文件导入Powershell

First Import Your CSV file into powershell

$AnyVariableName = Import-Csv "$env:USERPROFILE:\Desktop\directoryname.txt"

注意:在我的示例中,CSV文件的路径在我的桌面上,但在您的桌面上可能有所不同.

Note: In my example, the path to the CSV file is on my desktop, but it may be different in yours.

然后使用foreach循环重命名项目

Then use a foreach loop rename the items

foreach ($objName in $AnyVariableName){

  Rename-Item $objName.OldName $objName.NewName

}

这篇关于Powershell-通过“文件名"查找文件并基于CSV重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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