I have a batch file that copies files form one folder to another at a given time and date (set on Windows 7.0 Task Scheduler).
My problem is I need files with same name not to be overwritten, I have tried piping a echo command to respond to overwright prompt in CMD but files are still overwritten.
Code:
REM Schedule background backup of Sebia Files, COnfig files, and patinet files
echo off
REM May fail if PC off or Flash drive unavailble to add additonal flags to try later
REM /D No to overwrite existing files.
REM echo "No" | copy/-Y c:\source c:\Dest\
REM echo "No" | xcopy/-Y /s/z "C:\Users\haematology\Desktop\FolderA" "C:\Users\haematology\Desktop\FolderB"
rem S will copy all subfolders and files within them Y prevents any overwrite prompts D essentially copies anything newer than what is already in the destination
xcopy /s/z/Y/D "C:\Users\haematology\Desktop\FolderA" "C:\Users\haematology\Desktop\FolderB"
rem tIMESTAMP
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
rem echo datestamp: "%datestamp%"
rem echo timestamp: "%timestamp%"
rem echo fullstamp: "%fullstamp%"
msg * "Back up succesful!" %fullstamp%
Any input appreciated
EDIT:
echo "No" | xcopy/-Y /s/z "C:\Users\haematology\Desktop\FolderA" "C:\Users\haematology\Desktop\FolderB
or changing Y flag to -Y in
xcopy /s/z/Y/D "C:\Users\haematology\Desktop\FolderA" "C:\Users\haematology\Desktop\FolderB
does not seem to work, files with the same name will be overwriiten.