Renaming multiple text files based on their contents- Batch File/VB Script
Posted on 2014-11-17
I am trying to rename a series of .txt files in a directory according to a specific phrase/text in each given text file. Put differently and more specifically, I have 100 text files with arbitrary or random names but within each file is a unique phrase/text (something like: GEMSAM_IN_USD_GEMSIT_MKE/ GEMSAM_IN_USD_IT_USA_DATEX_LAU/ GEMSAM_IN_USD_GEMSIT_DTJ). I would like to replace the arbitrary file name with the **desired** file name.
For E.G. When I open the text file and find text "GEMSAM_IN_USD_GEMSIT_MKE" the file name should be renamed as MKE.txt or if I find "GEMSAM_IN_USD_IT_USA_DATEX_LAU" file name should be LAU.txt. The text/phrase is static and will not change.
I used the below mentioned syntax but nothing happened and I am clueless, and this is my first real foray into batch programming so the syntax is fairly new to me.
for /f "tokens=*" %%1 in ('type 502236373.123456.txt ^| find "GEMSAS_IN_JPY_DTYMS_JAPAN"') do (
set line=%%1&set line=!line:~1!
copy C:\Users\gk814256\Desktop\Docstore Test\new.txt
I am looking for Batch file or VB script or anything that meets my exact needs.
Any suggestions would be greatly appreciated!
I am looking forward for the positive response!!!!!!