What I want:
in an inputpath, there can be files and/or subdirectories with files. If these exist in the targetpath, then the the files in the targetpath need to be be renamed to file_OLD.extension.
When this is done the files from inputpath need to be copied there.
If the file, or sub directory with file not exists, the sub directory needs to be created and the file needs to be placed there.
What I have so far:
Code: Select all
@echo off
setlocal enabledelayedexpansion
set inputpath=P:\Deployment\1.DeployToTST\Template
set targetpath=\\<servername>\Template
for /f %%a in ('dir "%inputpath%"/a-d/b/-p/s^|find /v ""') do (
if exist %targetpath%\%%a (
xcopy "%targetpath%\%%a" "%targetpath%/%%a_OLD" /Y
xcopy /S "%%a" "%targetpath%\%%a" /Y /I /K
) ELSE (
xcopy /S "%%a" %targetpath\%%a%" /Y /I /K)
)
Code: Select all
P:\Deployment\1.DeployToTST\Template\template1.ctx
P:\Deployment\1.DeployToTST\Template\template1\template1.ctx
Code: Select all
template1.ctx
template1\template1.ctx