I have a batch script that copy files over a network. I want to log the time, error , and the result. So far I can log the successful result of the xcopy, log of timestamp works. My problem is it can't copy a file. And I also want to log the error if any.
here is my work in progress script.
@echo off
cd %~d0\
set curDrive=%~d0\
Title TEST File Backup Program v2.9.2
set logpath=%~d0\Backuplog\
Set t=%time:~0,2%%time:~3,2%
set filelog=FILE_%date:~0,3%%date:~4,2%%date:~7,2%%date:~10,4%_%t: =0%.log
set errorlog=erFILE_%date:~0,3%%date:~4,2%%date:~7,2%%date:~10,4%_%t: =0%.log
if exist %logpath% (goto Y) else (goto N)
:N
md %logpath%
:Y
NET USE \\hostname [password] /user:domain\domainuser
Set srcfileserver=\\hostname
Set destfileserver=%curDrive%hostname
rem Exclude files/folders with these name(s)
echo \RecycleBin\>%curDrive%xludbak.txt
echo ************************************************* >> %logpath%%filelog%
echo File Backup Started: %date% %time% >> %logpath%%filelog%
echo ************************************************* >> %logpath%%filelog%
echo My Shared Folder started... >> %logpath%%filelog%
date /t >> %logpath%%filelog%
time /t >> %logpath%%filelog%
for /f "tokens=*" %%i in ('xcopy %srcfileserver%\"My Shared Folder"\ %destfileserver%\"My Shared Folder"\/c/f/y/z/exclude:%curDrive%xludbak.txt') do (
echo [%date%, %time%] %%i >> %logpath%%filelog% 2>> %logpath%%errorlog%
)
echo My Shared Folder finished... >> %logpath%%filelog%
date /t >> %logpath%%filelog%
time /t >> %logpath%%filelog%
thanks in advance