如何从一批的名单在一个文本文件重命名目录中的文件 [英] How to batch rename files in a directory from a list of names in a text file
问题描述
我想使用电源外壳或批处理文件基于在一个文本文件列表的文件夹中重命名多个文件。基本上我想追加与作者的姓氏(我已经储存在一个单独的文本文件)的文件名。
I'd like to use Power Shell or a batch file to rename several files in a folder based on a list in a text file. Essentially I want to append the file names with the author's last names (which I have stored in a separate text file).
例如。目前,我有:
C:\\ myfiles的
C:\myfiles
9-ART-2013.pdf
4-EGO-2013.pdf
2-ART-2013.pdf
我的文本文件(以相同的顺序文件):
My text file (in same order as files):
C:\\ myfiles的
C:\myfiles
_Smith
_Jenkins
_McMaster
我想如下文件进行重命名:
I want the files to be renamed as follows:
9-ART-2013_Smith.pdf
4-EGO-2013_Jenkins.pdf
2-ART-2013_McMaster.pdf
我见过人们总是希望递归重命名文件类似的问题,但他们总是使用通用共同追加元素,如添加下划线或pre-等待与文件夹名称等。
I've seen similar problems where people want to recursively rename files but they are always using a generic common appending element like adding an underscore or pre-pending with folder name, etc.
例如。 <一href=\"http://serverfault.com/questions/6268/easy-way-to-rename-all-files-in-a-directory-in-windows\">http://serverfault.com/questions/6268/easy-way-to-rename-all-files-in-a-directory-in-windows
推荐答案
在PowerShell中这将是:
In PowerShell it would be:
$names = Get-Content c\myfiles
Get-ChildItem C:\somedir\*.pdf | Sort -desc |
Foreach {$i=0} {Rename-Item $_ ($_.basename + $names[$i++] + $_.extension) -WhatIf}
如果它看起来像它会正确复制,删除 -WhatIf
。
If it looks like it will copy correctly, remove the -WhatIf
.
这篇关于如何从一批的名单在一个文本文件重命名目录中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!