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
extracting characters from file name
Moderator: DosItHelp
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Your post is confusing. Is testYYMM.txt always the filename that you want to extract the YYMM from? Then:
If that's not what you mean, then please elaborate.
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