1.

Solve : DIR?

Answer»

Hi All,
I am trying to move a file to a new location with a bat file. The problem is that the path of the new location CHANGES at the begining of the MONTH. For example this month.....

\\server\backup\new\monthyear\file
or
\\server\backup\new\August2012\20120808.sdc.txt

the next month it will be
\\server\backup\new\September2012\20120908.sdc.txt

I can change the file name to the system time but I don't know how to change a folder in the path.

Thanks
Can I see the output of your DATE variable.
Open up a CMD prompt and type the following command.
Code: [Select]echo %date%Here's a region independent method using wmic.

@Squashman: there are so many different ways of getting the timestamp - if the OS can run Wmic then it's easy, no hassle with leading spaces or rearranging dates. It's simpler.

Code: [Select]@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set stamp=%dt:~0,4%-%dt:~4,2%-%dt:~6,2%_%dt:~8,2%-%dt:~10,2%-%dt:~12,2%
set year=%dt:~0,4%

if "%dt:~4,2%" EQU "01" set month=January
if "%dt:~4,2%" EQU "02" set month=February
if "%dt:~4,2%" EQU "03" set month=March
if "%dt:~4,2%" EQU "04" set month=April
if "%dt:~4,2%" EQU "05" set month=May
if "%dt:~4,2%" EQU "06" set month=June
if "%dt:~4,2%" EQU "07" set month=July
if "%dt:~4,2%" EQU "08" set month=August
if "%dt:~4,2%" EQU "09" set month=September
if "%dt:~4,2%" EQU "10" set month=October
if "%dt:~4,2%" EQU "11" set month=November
if "%dt:~4,2%" EQU "12" set month=December

set foldername=%month%%year%

echo copy /b "file.txt" "\\server\backup\new\%foldername%\file-%stamp%.txt"

pauseecho %date%
Mon 08/13/2012



Discussion

No Comment Found