Here is a possible solution:
@echo off
setlocal EnableDelayedExpansion
set month[01]=Jan
set month[02]=Feb
set month[03]=Mar
set month[04]=Apr
set month[05]=May
set month[06]=Jun
set month[07]=Jul
set month[08]=Aug
set month[09]=Sep
set month[10]=Oct
set month[11]=Nov
set month[12]=Dec
for /f "tokens=2 delims==" %%A in ('wmic OS Get localdatetime /value') do set "dt=%%A"
set "YY=%dt:~2,2%" & set "MM=%dt:~4,2%"
copy "C:\TESTone\*.*" "C:\!month[%MM%]!-%YY%"
move "C:\TESTone\*.*" "\\172.1.1.1\Shared-File\!month[%MM%]!-%YY%\"
pause
- Enabling delayed expansion will help here, since we will need it here, neither inside a code block nor using it when setting and using variable in one line. It will help since we want to echo a variable whose value is the name of another variable.
- Setting array of months. We use form
varname[monthnum]
.
- Finding
date
requires wmic
, else it won't be international the same. The date
and time
environment variables are defined by user and they usually depend on user regional settings.
- Now, setting the last two digits of the year are stored into the
YY
variable and the two digits of the month are stored in MM
variable.
- The command that OP wanted was
copy "C:\TESTone\*.*" "C:\MMM-YY"
and move "C:\TESTone\*.*" "\\172.1.1.1\Shared-File\MMM-YY\"
. So, YY
is just ready, we have:
copy "C:\TESTone\*.*" "C:\MMM-%YY%"
move "C:\TESTone\*.*" "\\172.1.1.1\Shared-File\MMM-%YY%\"
MMM
is the value of variables month[MM]
. So, using here delayed expansion; wrapping number variables with !
and MM
with %
. It will be:
copy "C:\TESTone\*.*" "C:\!month[%MM%]!-YY"
move "C:\TESTone\*.*" "\\172.1.1.1\Shared-File\!month[%MM%]!-YY\"
and then:
copy "C:\TESTone\*.*" "C:\!month[num]!-YY"
move "C:\TESTone\*.*" "\\172.1.1.1\Shared-File\!_num!-YY\"
and then being processed which is actually what OP requested.