Another Bat Q for Renaming using filecontents

December 13, 2010 at 16:08:40
Specs: Windows 7
I'm new to coding this stuff, and I've got a similar question to what's been posted before, and I've tried to modify the responses to work with my situation, but just don't know enough to get a version working.

I have a directory of ascii data files where the second line of each file is always in the format:
F1 1251040A0

I'd like to rename each file in the dir to the characters following the "F1 ". with a custom extension.
So for the above example, the file where its' entire second line is:
F1 12851040A0
renamed to:

another example:
F1 50-1056-06 TAB
renamed to:
50-1056-06 TAB.PX

as some of the text following the F1 might contain spaces.

is this possible?
Since I have multilple files, would I use a nested FOR statement?

I'd appreciate any help you could give.

See More: Another Bat Q for Renaming using filecontents

Report •

December 14, 2010 at 02:11:15
@echo off & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b *.dat') do (
  call :sub1 %%a
goto :eof

  for /f "skip=1 tokens=2 delims= " %%i in (%1) do (
    set F=%%i
    goto :done
  ren %1 !F!.PX
goto :eof

Life is too important to be taken seriously.


Report •

December 14, 2010 at 08:27:00
Thank you M2!

That works perfectly for all the files that don't contain a space (the majority of my files). I'll kick it around a bit to see if I can get that part working.

I appreciate your time and your response. You guys are great!

Report •
Related Solutions

Ask Question