0

I need help in finding what AM'I doing wrong here in the batch script. I'm able to copy files to first destination, ie EmployeeData Folder. There is second folder in EmployeedataFolder, called BackUpforEmployeeData, in which I'm unable to copy the same file with date appended.

The first destination, It has to replace the file, Second destination, it should copy files with appended date. No prompts for action is needed, as i have scheduled it on a task scheduler. Please help!

@echo off

xcopy "\\Source\hr\Employee.txt" "E:\EmployeeData" /Y

@echo off



rem set YYYY=%dt:~0,4%

rem set MM=%dt:~4,2%

rem set DD=%dt:~6,2%

rem set stamp=%YYYY%-%MM%-%DD%

xcopy "\\Source\hr\Employee.txt" "E:\EmployeeData\BackUpForEmployeeData\Employee_%DATE% /Y 
/I /S

Pause
Compo
  • 34,184
  • 4
  • 22
  • 36
SaraDob
  • 79
  • 11
  • 1
    Where are you setting the %dt% variable? I'd suggest first setting your date variables. This article may help: [StampMe.cmd](https://ss64.com/nt/syntax-stampme.html) – Qwerty Apr 26 '22 at 19:32
  • I have commented out all the sate setting variables. Even then Im not getting the file copied. – SaraDob Apr 26 '22 at 19:39
  • If it is a single file, you can just use the copy command. UNC paths are not supported for xcopy. You can use the net use command to map the drive first. [UNC paths and xcopy](https://stackoverflow.com/questions/56257565/unc-paths-are-not-supported) – Qwerty Apr 26 '22 at 19:47
  • 1
    @SaraDob, I have replaced your image showing your code, with a matching version within a code box, without issue. The variable `%DATE%` will most likely contain characters which are not supported in Windows file or directory names, there is a missing closing double quote on line 17, and an invalid CRLF at the end of that line. In addition, and as already mentioned, your `rem`arked lines are modifying a variable which has never been defined within the code, _(that should be defined within a remarked line too)_. – Compo Apr 26 '22 at 20:06
  • Now that it is working, even with /i and /y, and @echo off, it is still prompting to check if this is a file or directory. I looked at all the options to make it file. I could not find one. can anyone help? – SaraDob Apr 26 '22 at 20:26
  • use `echo f|xcopy...` to automatically reply `f` to the query – Magoo Apr 26 '22 at 23:30

0 Answers0