extracting characters from file name

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mbourgeault
Posts: 2
Joined: 01 Jun 2009 09:52

extracting characters from file name

#1 Post by mbourgeault » 01 Jun 2009 10:05

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

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 01 Jun 2009 11:43

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.

mbourgeault
Posts: 2
Joined: 01 Jun 2009 09:52

#3 Post by mbourgeault » 01 Jun 2009 14:11

this will probably work...thank you

Post Reply