Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
spupuz
- Posts: 2
- Joined: 12 Sep 2013 07:32
#1
Post
by spupuz » 12 Sep 2013 07:38
i need to create a batch file that copy a file that is of the month previous of the actual and the name is in this:
file_aug_2013.txt
the nex month will be
file_sep_2013.txt
how can i use wild cards to make it work correctly?
@echo off
set Year=%Date:~6,4%
@echo off
set Year=%Date:~6,4%
@echo off
SET Month=%DATE:~3,2%
echo %Month%
if %Month%==01 set Month=JAN
if %Month%==02 set Month=FEB
if %Month%==03 set Month=MAR
if %Month%==04 set Month=APR
if %Month%==05 set Month=MAY
if %Month%==06 set Month=JUN
if %Month%==07 set Month=JUL
if %Month%==08 set Month=AUG
if %Month%==09 set Month=SEP
if %Month%==10 set Month=OCT
if %Month%==11 set Month=NOV
if %Month%==12 set Month=DEC
echo %Month%
echo %Year%
i need to subtract actual month (i launch this copy first day of the month taking the log of the previous month) and make a copy command
-
aGerman
- Expert
- Posts: 4743
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 12 Sep 2013 11:32
Try:
Code: Select all
@echo off &setlocal
for %%i in (
"1=JAN","2=FEB","3=MAR","4=APR","5=MAY","6=JUN","7=JUL","8=AUG","9=SEP","10=OCT","11=NOV","12=DEC"
) do set "m%%~i"
set /a "Year = %Date:~6,4%, Month = 1%DATE:~3,2% %% 100"
if %Month%==1 (set /a "PrevMonth = 12, PrevYear = Year - 1") else set /a "PrevMonth = Month - 1, PrevYear = Year"
call set "Month=%%m%Month%%%"
call set "PrevMonth=%%m%PrevMonth%%%"
echo file_%PrevMonth%_%PrevYear%.txt
echo file_%Month%_%Year%.txt
pause
What I don't understand is why do you think you need wildcards
Regards
aGerman
-
spupuz
- Posts: 2
- Joined: 12 Sep 2013 07:32
#3
Post
by spupuz » 12 Sep 2013 11:43
I'll test it tomorrow thanks for now