Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Batch file version of "on error resume nest"

Posted on 2011-03-24
3
Medium Priority
?
808 Views
Last Modified: 2012-05-11
I have a batch file to copy logs from single servers to a shared loaction. It seems that if any of the files in the source directory are locked or in use the whole batch file command set fails and issues and exit code of 4. Is ther a line to add to tell the commands if there is an error with any of the files to copy to just move on to the next. Batch file is as follows.

@echo off
set T=%time:~0,5%
set dir=%date:/=-% %T::=-%
echo The target folder is "%dir%".
mkdir "\\usmoksc5app55\text\usmoksc5app27\%dir%"
xcopy /L "D:\GCTI\Logs\*.*" >  "\\usmoksc5app55\text\usmoksc5app27\%dir%\%date:/=-% %T::=%.log"

xcopy /s /c /y "D:\GCTI\Logs\ksc_sip_pri\Archive\*.*" "\\usmoksc5app55\logs\usmoksc5app27\%dir%\"
0
Comment
Question by:charlespliler
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 30

Expert Comment

by:Randy Downs
ID: 35211109
You could put these in your code.
on error goto

Here's a sample - http://newton.freehostia.com/net/batch/batguide.html
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 1000 total points
ID: 35211418
Forget that link. It is so 90's. Nowadays we have much more powerful batch options - but nothing like "on error resume next". Because that is the "default", as long as no fatal error occurs.

I needed several goes to understand what you try to achieve. But I wonder if you really want only the top level files of D:\GCTI\Logs logged into the logfile.
Since %dir% is exactly the same as your logfile name, it sounds a bit superfluous, as date and time is in both the folder and the file name.
Nevertheless, constructing the file name is unnecessary, as you have it in %dir% already:
   xcopy /L "D:\GCTI\Logs\*.*" >  "\\usmoksc5app55\text\usmoksc5app27\%dir%\%dir%.log"

Further, I would rather format the time portion in %dir% like that:
   set dir=%date:/=-% %time:~0,2%-%time:~3,2%

Last note: RoboCopy should be preferred over XCopy. Latter is considered "depricated" since Vista. RoboCopy allows for much more robust copies, repeating until success or an error counter is reached, and many options more.
0
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 35211701
I also use robocopy amd set it for 1 retry in 1 second. This basically just skips files that don't exist.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question