Trying to get my batch to not span to multiple directories and scratching my head as to why its doing this.
When I look at the %date% I get this format:
C:\Users\user1>echo %date%
Sun 01/14/2018Which I replace / with - at the start of the batch
C:\Users\user1>echo %date:/=-%
Sun 01-14-2018Here is what I put together so far. And it passes the data to:
C:\test2\sun 01\14\2018\
in which I would like the data to be in a path such as:
C:\test2\sun 01-14-2018\
Initially I thought it was flipping the / to \ to make for the folder creation depth, but even with / replaced with - in %date% its still doing the same thing. This is probably a pretty easy thing to correct but stuck after 45 minutes on this and google isnt a help at this point.
echo off
cd\.
cd test2
set datefix=%DATE%
set datefix=%DATE:/=-%
cls
@echo. Running Backup
@echo.
@echo.
@echo. Backup ... Creating Folder with todays date
@echo.
for /f "tokens=1* delims=" %%a in ('date /T') do set datestr=%%a
mkdir %datestr%
@echo.
@echo. Backup ... Folder Created with todays date
@echo.
@echo. Backup ... XCopying Important Data to new backup location for %date%
@echo.
xcopy c:\test1\*.* "c:\test2\%datestr%\*.*" /s/d/y/h
@echo.
@echo. Backup ... Important Data has been backed up
@echo.
pause
On my last attempt at trying to get this to work it breaks %date% and dumps the data directly to C:\test2\ with replacing date with datefix. I assumed in the first batch above that it would keep to the formatting of replacement of / with - but it didnt seem to, so I thought maybe I am overlooking the fact that date in the for loop needs to be replaced with datefix which is taking the identity of %date% but with the / to - replacement in formatting with the batch below that copies data to C:\test2\ but doesnt create the folder with todays date.
echo off
cd\.
cd test2
set datefix=%DATE%
set datefix=%DATE:/=-%
cls
@echo. Running Backup
@echo.
@echo.
@echo. Backup ... Creating Folder with todays date
@echo.
for /f "tokens=1* delims=" %%a in ('datefix /T') do set datestr=%%a
mkdir %datestr%
@echo.
@echo. Backup ... Folder Created with todays date
@echo.
@echo. Backup ... XCopying Important Data to new backup location for %date%
@echo.
xcopy c:\test1\*.* "c:\test2\%datestr%\*.*" /s/d/y/h
@echo.
@echo. Backup ... Important Data has been backed up
@echo.
pause