Find/Findstr, copy, rename combo

May 10, 2011 at 09:47:08
Specs: Windows 7

Ok, here is my problem.

I have one text file called test.txt. Inside test.txt is a lot of data but only one string that starts with@ followed by a random number. The number changes with each version of test.txt



I need a batch file to read through test.txt, find the number behind the @, then copy another file file (call it new.txt) out of a different folder and reame it so it adds the number to its file name.

So in the above example, I would search test.txt, find the number 471, copy new.txt from folder c:\abc to folder d:\xyz and rename new.txt to 471new.txt

Oh and yes, batch file is really the only option. Thanks in advance!

See More: Find/Findstr, copy, rename combo

Report •

May 11, 2011 at 02:21:15

@echo off
setlocal enabledelayedexpansion

for /f "tokens=*" %%1 in ('type test.txt ^| find "@"') do (
    set line=%%1&set line=!line:~1!

copy c:\abc\new.txt d:\xyz\%line%new.txt>nul

Please come back & tell us if your problem is resolved.

Report •

May 11, 2011 at 10:45:02
Worked like a charm! Would never have figured that one out myself, thanks so much! :)

Report •

May 11, 2011 at 22:01:09
You're welcome, thanks for coming back to report your success.

Please come back & tell us if your problem is resolved.

Report •

Related Solutions

Ask Question