Solved

Batch file version of "on error resume nest"

Posted on 2011-03-24
3
794 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 70

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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

696 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