Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename the files in the path with new different names in batch?

Tags:

I have one file destination.txt with path information about my CDs:

 C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\SME99.ISO
C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\Biomasse.iso 
C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\SAMPE36.ISO

Now I have to rename the ISOs with the numbers that are in the file PPN.txt one after another:

470692405 
394006801 
348117876 

So it should be

SME99.ISO -> 470692405.ISO
Biomasse.iso -> 394006801.ISO
Sampe36.ISO -> 348117876.ISO

I have the following code for it:

< "PPN.txt"  (for /F "usebackq delims=" %%a in ("destination.txt") do (
  set/P out="" & rename "%%a" "!out!%%~xa" 

I want to modify the code that way that it works for the file destination.txt:

Success on: "C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\SME99.ISO" 
Error on:   "C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\Biomasse.iso" 
Success on: "C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\SAMPE36.ISO" 

If "Success on" stays before the path in destination.txt the image should be renamed as always only with the number from PPN.txt. But if "Error on" stays before the path in destination.txt the image should be renamed like this e_%number from PPN.txt% . So it should be additional prefix e_ there