LuiLui77
asked on
Batch file to copy folder and content
Hello All,
I am looking for a batch file that will help me on copying content over the network from one computer to another. This batch file will need to rename every copy with the current date of the copy since I am trying to make a backup of the same directory for 5 days.
Can anyone share this batch?
I am looking for a batch file that will help me on copying content over the network from one computer to another. This batch file will need to rename every copy with the current date of the copy since I am trying to make a backup of the same directory for 5 days.
Can anyone share this batch?
ASKER
Hi NewVillageIT, yes, placing the files in a dated folder will suffice
Note:
- Please do a test folder first. Preferably, a smaller source folder to see quick results.
- Results are sent to a log in the %temp% folder.
- Please do a test folder first. Preferably, a smaller source folder to see quick results.
- Results are sent to a log in the %temp% folder.
call :DateTime-YYMMDDHHMMSSUU
set FNLog=%temp%\%DateTimeNow%
set SDir=\\svr1\share
set TDir=\\svr2\share\%DateTimeNow%
if "%DateTimeNow%" equ "" echo Error making dated folder name>>"%FNLog%"
if not exist "%TDir%" md "%TDir%"
xcopy "%SDir%" "%TDir%" /s /f /h /y>>"%FNLog%"
goto :eof
:DateTime-YYMMDDHHMMSSUU
set DateTimeNow=
set Dt=%date%
set Tm=%time%
REM e.g.
REM Fri 12/19/2014
REM 8:20:04.13
for /f "tokens=2-4 delims=/ " %%a in ("%date%") do (set MM=%%a& set DD=%%b& set YY=%%c)
for /f "tokens=1-4 delims=/:." %%a in ("%time%") do (set /a Hr=%%a& set Min=%%b& set Sec=%%c& set Mic=%%d)
REM If the hour is single digit, prefix it with a zero.
if %Hr% lss 10 set Hr=0%Hr%
set DateTimeNow=%YY%%MM%%DD%%Hr%%Min%%Sec%%Mic%
for %%a in (Dt Tm MM DD YY Hr Min Sec Mic) do (set %%a=)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No worries π Steve. Have a good one.
Does it have to rename each file? Or, will placing the files in a dated folder suffice?