How to rename the files in the path with the new names from the .txt file in batch?

笑着哭i 提交于 2019-12-02 01:34:54

问题


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 

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


回答1:


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.



来源:https://stackoverflow.com/questions/43005718/how-to-rename-the-files-in-the-path-with-the-new-names-from-the-txt-file-in-bat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!