Page 1 of 1

extracting characters from file name

Posted: 01 Jun 2009 10:05
by mbourgeault
I am looking for a way to extract a 2 digit year and 2 digit month that is in a file name and save them off to a text file named 'test<2digityear><2digitmonth>.txt'.

ie: test0905.txt

want to extract the 0905 and store is as the content of LoadDate.txt

Any help would be greatly appreciated
Thank you

Posted: 01 Jun 2009 11:43
by avery_larry
Your post is confusing. Is testYYMM.txt always the filename that you want to extract the YYMM from? Then:

Code: Select all

set filename=test0905.txt
:: Or you could pass the filename with set filename=%~1
:: Or you could do a for loop and then set filename=%%~a
:: with the for loop you'll have to use enabledelayedexpansion
set year=%filename:~4,2%
set month=%filename:~6,2%

:: or like this
echo.%filename:~4,4%>loaddate.txt
If that's not what you mean, then please elaborate.

Posted: 01 Jun 2009 14:11
by mbourgeault
this will probably work...thank you