如何使用.txt文件中的新名称重命名路径中的文件? [英] How to rename the files in the path with the new names from the .txt file in batch?

查看:66
本文介绍了如何使用.txt文件中的新名称重命名路径中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个.txt文件.第一个包含CD映像的路径列表:

I have two .txt files. The first one contains the list of pathes to the CD-Images:

C:\Users\N\Desktop\LOG_Dateien_CD_Imaging\BFU_KONGRESS_9.ISO   
C:\Users\N\Desktop\LOG_Dateien_CD_Imaging\NDC2005.ISO 

第二个包含该文件的新名称

The second one contains the new names for this files

490628001
684654326 

因此,目录(而不是.txt文件中的文件)中的文件BFU_KONGRESS_9.ISO应该重命名为490628001.ISONDC2005.ISO684654326.ISO.重命名应该一行一行

So the file BFU_KONGRESS_9.ISO in the directory (not in the .txt file!) should be renamed to 490628001.ISO and NDC2005.ISO to 684654326.ISO. The renaming should go line per line

推荐答案

您需要一种并行读取两个文件的方法:

you need a way to read two files in parallel:

@echo off
setlocal enabledelayedexpansion

<out.txt (
  for /f "delims=" %%a in (in.txt) do (
    set /p out=
    echo rename "%%~a" "!out!"
  )
)

另一种方法:将两个文件(一个接一个)读取到两个数组中,然后使用数组变量,但这是更多代码,并且对于很大的文件可能会出现问题.

Another way: read both files (one after the other) into two arrays and then work with the array variables, but it's more code and might have issues with very large files.

这篇关于如何使用.txt文件中的新名称重命名路径中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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