xcopy - Log and xcopy skip to next.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
lienlee
Posts: 3
Joined: 09 Jun 2011 08:35

xcopy - Log and xcopy skip to next.

#1 Post by lienlee » 09 Jun 2011 08:43

Hi Guys!

I'm new to the forums and a complete novice at dos batch.

I have the following code here to log my xcopy scripts and run the xcopy

Code: Select all

@echo on
setlocal
set /a counter=0

xcopy1 >> copylog.txt && set /a counter+=1
xcopy2 >> copylog.txt && set /a counter+=1

if %errorlevel% equ 0 (echo success >> copylog.txt) else (echo failure >> copylog.txt)
echo.%counter% of xcopys were run successfully >> copylog.txt
echo. >>copylog.txt


The assistance I require is that the current code only prints out the Source path when it's successful, however, it does not print out the unsucessful xcopies. I need a code so it prints out the unsucessful xcopy - source path.

Secondly, one of the many problems with programming is the string name. I'm currently copying files over to other folders and sometimes the file may have a extra space somewhere in the file name.

Currently all the existing file names for all the files I have are currently in a Excel Spreadsheet, however, they're probably not the exact name or there may be extra space somewhere. I need to adjust the xcopy so that it will go to the next xcopy if such situations exists, so i can proceed to the next xcopy

Your help is much appreciated!

Thank you!

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: xcopy - Log and xcopy skip to next.

#2 Post by Ed Dyreen » 09 Jun 2011 09:09

Code: Select all

@echo on
setlocal
set /a counter=0


( xcopy1 ) 2>&1>>copylog.txt && set /a counter+=1
( xcopy2 ) 2>&1>>copylog.txt && set /a counter+=1

if %errorlevel% equ 0 (echo success >> copylog.txt) else (echo failure >> copylog.txt)
echo.%counter% of xcopys were run successfully >> copylog.txt
echo. >>copylog.txt

pause
exit

lienlee
Posts: 3
Joined: 09 Jun 2011 08:35

Re: xcopy - Log and xcopy skip to next.

#3 Post by lienlee » 09 Jun 2011 09:57

Ed Dyreen wrote:

Code: Select all

@echo on
setlocal
set /a counter=0


( xcopy1 ) 2>&1>>copylog.txt && set /a counter+=1
( xcopy2 ) 2>&1>>copylog.txt && set /a counter+=1

if %errorlevel% equ 0 (echo success >> copylog.txt) else (echo failure >> copylog.txt)
echo.%counter% of xcopys were run successfully >> copylog.txt
echo. >>copylog.txt

pause
exit


Hi, thanks for the quick response, but could you explain what you did and the changes, so I can educate myself =)
I notice the only changes were to skip to the next xcopy.

The current code only prints out the Source path when it's successful in the log file, however, it does not print out the unsucessful xcopies. I need a code so it prints out the unsucessful xcopy - source path to the logfile.

Thank you!

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: xcopy - Log and xcopy skip to next.

#4 Post by Ed Dyreen » 10 Jun 2011 12:58


I need a code so it prints out the unsucessful xcopy - source path to the logfile.

Didn't test this code. 2>>copylog.txt should catch errors to the logfile normally.

Code: Select all

@echo on
setlocal
set /a counter=0

set /a $error = 0
( 2>&1>>copylog.txt xcopy1 ) &&set /a counter+=1 ||set /a $error = %errorlevel%
( 2>&1>>copylog.txt xcopy2 ) &&set /a counter+=1 ||set /a $error = %errorlevel%

if %$error% equ 0 (echo success >>copylog.txt ) else ( echo failure >>copylog.txt )
>>copylog.txt (
   echo.%counter% of xcopys were run successfully
   echo.
)

pause
exit /b

Post Reply