批量编辑txt名称


0

我在Windows 7上有一个txt文件夹,所有txt都被命名

keyword_uniqueFileName.txt

keyword_uniqueFileName2.txt

keyword_uniqueFileName3.txt

并希望批量更改为

MyNewKeyword_uniqueFileName.txt

MyNewKeyword_uniqueFileName2.txt

MyNewKeyword_uniqueFileName3.txt

使用某些程序或命令行。

最糟糕的情况我将不得不去我的Kubuntu机器并在那里使用一些命令。

Answers:


1

在命令行窗口(“DOS框”)中,尝试

ren keyword_uniqueFilename*.txt MyNewKeyword_uniqueFilename*.txt

但是我将不得不修改每个文件的命令?
user1603548 2014年

@ user1603548不,如果您的文件名在问题中列出并且应该按照问题中的列出进行修改,那么这一行命令将完全按照需要执行重命名。
Hagen von Eitzen 2014年


0

使用powershell:

powershell -C "gci | % {rni $_.Name ($_.Name -replace 'keyword', 'MyNewKeyword')}"

说明

powershell -C "..."启动PowerShell会话以运行带引号的命令。命令完成后,它返回到外壳。-C是的缩写-Command

gci返回当前目录中的所有文件。它是[ Get-ChildItem] [gci] 的别名。

| % {...}制作一个管道来处理每个文件。%是[ Foreach-Object] [%] 的别名。

$_.Name 是管道中当前文件的名称。

($_.Name -replace 'KW1', 'KW2')使用-replace运算符创建新文件名。第一个子字符串的每次出现都被第二个子字符串替换。

rni更改每个文件的名称。第一个参数(被调用-Path)标识文件。第二个参数(被调用-NewName)指定新名称。rni是[Rename-Item] [rni]的别名。

参考

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.