-1

I have a file folder.txt file with a list of folder names on the HDD that have to be renamed with the names from gbv.txt. So the first line from folder.txt should be renamed with the first line from gbv.txt and so on. The folders are in the same directory from where the script will be started.

folder.txt

F-93-B-109
F-93-B-122
F-93-B-148
F-93-B-157

gbv.txt

GBV529357402
GBV52935795X
GBV529360799
GBV529362236

I'm slightly new to batch and don't know how to use rename in this situation in the loop

Squashman
  • 13,649
  • 5
  • 27
  • 36
Oleg_08
  • 447
  • 1
  • 4
  • 23
  • 15 months on SO asking batch file questions. Figured you would be a seasoned veteran answering questions by now. – Squashman Mar 06 '18 at 19:41
  • 1
    Just looked back at your last [batch file question](https://stackoverflow.com/questions/45237964/how-to-rename-the-files-in-the-path-with-new-different-names-in-batch). You are essentially doing the same thing. This tells me you are not even trying to understand the code that is given to you. – Squashman Mar 06 '18 at 19:56
  • 2
    Please note that https://stackoverflow.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask). – DavidPostill Mar 06 '18 at 20:48

1 Answers1

0

Essentially to read two files at a time you need to use a FOR /F command to read one file and stream the other file into the FOR /F command block. When you do this, you then can use the SET /P command to capture the line of text from the file being streamed into the command block.

@echo off
setlocal enabledelayedexpansion

< gbv.txt (FOR /F "delims=" %%G IN (folder.txt) DO (
    set /p newname=
    echo rename "%%G" "!newname!"
    )
)
pause

The output on the screen will look like this.

C:\BatchFiles\SO>so.bat
rename "F-93-B-109" "GBV529357402"
rename "F-93-B-122" "GBV52935795X"
rename "F-93-B-148" "GBV529360799"
rename "F-93-B-157" "GBV529362236"
Press any key to continue . . .

When the output looks good, remove the word echo before the rename in the script.

Squashman
  • 13,649
  • 5
  • 27
  • 36