Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
DOS/Other
Tag Cloud
access acer asus batch bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming gpu hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > DOS/Other >
Solved: batch file - show if error

Reply  
Thread Tools
danniy's Avatar
Computer Specs
Junior Member with 29 posts.
 
Join Date: Oct 2007
Location: Romania/Bucharest
Experience: Intermediate
08-Sep-2010, 03:21 PM #1
Solved: batch file - show if error
Hello

I am new in making batch files. I only write VBA excel and access code.

I made a simple file that contains a copy command.

Code:
copy "\\...........SQ_TEMP\DealExport1_v1.xlsm" "C:\Program Files\Microsoft Office\Office12\XLSTART"
As you see this bat just copies the xlsm file from a sharepoint to a local folder. It works fine, but if the xlsm file is in use, or the user has no access to the sharepoint it doesn't work. Thats fine by me, but i just want to see when it is not working.

What i want is a simple code to add to this copy line that will tell the user when the file cannot be copied.
Is that possible?

Thank you.
danniy
Ent's Avatar
Ent Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 3,237 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
08-Sep-2010, 03:45 PM #2
Have a look into the IF command, particularly IF Errorlevel.
danniy's Avatar
Computer Specs
Junior Member with 29 posts.
 
Join Date: Oct 2007
Location: Romania/Bucharest
Experience: Intermediate
08-Sep-2010, 06:03 PM #3
i tried but i got lost in all the numbers. lots of error levels and i have no idea how to write the if in a batch file.

for example in vba it's pretty simple:

Code:
If "condition" Then
"do something"
Else
"do something else"
End if
what i need here is something like:

if error "copy............."
show error message.
End if

something like that. I have no idea what level or how should i put this into code.


i got something like:

copy....
if ErrorLevel 1 echo error


this works but i get to see the error message for 1 sec and window closes

Last edited by danniy; 08-Sep-2010 at 06:43 PM..
Ent's Avatar
Ent Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 3,237 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
08-Sep-2010, 06:32 PM #4
If you're dealing with batch, you have to get out of the mindset which VBA puts you in.

Try the following line AFTER the copy command

if errorlevel 1 echo Something didn't work there. Please check that you have access to the file and it is not in use.
__________________
Quod non mortiferum, fortiorem me facit.
I don't read minds. Please help everyone by answering any questions and reporting on the results of any suggestions.
danniy's Avatar
Computer Specs
Junior Member with 29 posts.
 
Join Date: Oct 2007
Location: Romania/Bucharest
Experience: Intermediate
08-Sep-2010, 06:46 PM #5
tried that. window closes immediately. cannot see the message.
can i get a textbox or something?
Ent's Avatar
Ent Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 3,237 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
08-Sep-2010, 06:48 PM #6
There are, to the best of my knowledge, no text boxes in batch. If you place the command "pause" at the end of your script it should give you time to see the message.
danniy's Avatar
Computer Specs
Junior Member with 29 posts.
 
Join Date: Oct 2007
Location: Romania/Bucharest
Experience: Intermediate
08-Sep-2010, 06:53 PM #7
ok, did it. thank you so much for your help, and time.

Danniy
Ent's Avatar
Ent Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 3,237 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
08-Sep-2010, 07:13 PM #8
You're welcome. I remember trying batch for the first time after using the Basic family. I still call it a duct tape & chewing gum language; effective and invaluable for what it is but incredibly annoying when you want a bit more discipline in a language. Good luck.

Ent
danniy's Avatar
Computer Specs
Junior Member with 29 posts.
 
Join Date: Oct 2007
Location: Romania/Bucharest
Experience: Intermediate
09-Sep-2010, 03:54 AM #9
well, i approve but im just using it to copy a file from a sharepoint. so no big deal here
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
09-Sep-2010, 08:57 AM #10
Quote:
Originally Posted by Ent View Post
You're welcome. I remember trying batch for the first time after using the Basic family. I still call it a duct tape & chewing gum language; effective and invaluable for what it is but incredibly annoying when you want a bit more discipline in a language. Good luck.

Ent
Then you should try PowerShell!
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
09-Sep-2010, 09:02 AM #11
Quote:
Originally Posted by danniy View Post
i tried but i got lost in all the numbers. lots of error levels
If you would have Google searched for "batch errorlevel" the first link Google would have found was this.
http://www.robvanderwoude.com/errorlevel.php

And you would have read this in the 2nd paragraph
Quote:
Most programmers agree that an errorlevel 0 means the command executed successfully, and an errorlevel 1 or higher usually spells trouble.
In my experience with batch, in your example you should really check to see if the errorlevel is NOT zero.

The link also provides plenty of examples of IF statements.
danniy's Avatar
Computer Specs
Junior Member with 29 posts.
 
Join Date: Oct 2007
Location: Romania/Bucharest
Experience: Intermediate
09-Sep-2010, 04:43 PM #12
thank you very much.
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools


Similar Threads
Title Thread Starter Forum Replies Last Post
Solved: How to write a batch file to amend a registry key?? lpool1 Software Development 18 30-Apr-2010 11:33 AM
Create a batch file to open a certain file in a certain file themusikid Windows 7 2 20-Nov-2009 02:29 AM
Batch File For/If Loop issue. MysticPixie Software Development 14 09-May-2009 11:09 PM
Solved: Batch file to del *.txt files from a dir older than today odewallrus DOS/Other 8 24-Feb-2009 01:07 PM
batch file to read from input file jpmg DOS/Other 6 30-Aug-2008 04:14 AM


Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:05 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.