Solved

Batch file version of "on error resume nest"

Posted on 2011-03-24
3
776 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 68

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

18 Experts available now in Live!

Get 1:1 Help Now