The file I want to work with is in C:\folder1\subfolder2 but has a file basename containing a variable date, i.e. company_yyyyMMdd.zip
I want to define a variable named fileyear, by searching C:\folder1\subfolder2\company*.zip, containing the four digit year string.
So far my code is:
@echo off
setlocal
for /f %%a in ("C:\folder1\subfolder2\company*.zip") do set fileyear=%%a:~7,4% & echo %fileyear%
I expect echo %fileyear% to output 2022
I did a test in cmd like this:
set FILENAME=company_20221215.zip
echo %FILENAME:~7,4%
It said 2022 just like I wanted.
7 means start at the 7th position and the 4 means read the next 4 digits.