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?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
> ...will need to rename every copy with the current date of the copy
Does it have to rename each file? Or, will placing the files in a dated folder suffice?
LuiLui77Author Commented:
Hi NewVillageIT, yes, placing the files in a dated folder will suffice
NVITEnd-user supportCommented:
- 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.


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

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=)

Open in new window

Steve KnightIT ConsultancyCommented:
I'd probably just rename them numbering 1 to 5 say:


@echo off
Set source=\\server\share
Set dest="C:\mydir"
pushd %dest%
if exist 5_%file% del 5_%file% 2>NUL
rename 4_%file% 5_%file% 2>NUL
rename 3_%file% 4_%file% 2>NUL
rename 2_%file% 3_%file% 2>NUL
rename 1_%file% 2_%file% 2>NUL
rename %file% 1_%file% 2>NUL
copy %source%\%file% %dest%

[Edit: bit slow posting there, didn't know NVIT had posted too...]

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NVITEnd-user supportCommented:
No worries 😊 Steve. Have a good one.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.