Solved

Batch file version of "on error resume nest"

Posted on 2011-03-24
3
783 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
3 Comments
 
LVL 29

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 69

Accepted Solution

by:
Qlemo earned 250 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 38

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Notepad++ how to remove delimiter : from beggning of the line? 3 100
Messed up my code 6 41
batch file problem 5 45
VB Script: create txt file with DateStamp and IP Adress 6 22
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now