Congratulations to AcaCandy on her 100,000th post!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen boot bsod computer connection crash css dell driver drivers email error ethernet excel firefox firefox 3 game hard drive internet internet explorer itunes laptop linux malware monitor network networking nvidia outlook outlook 2003 outlook 2007 outlook express partition problem router slow software sound trojan usb video virus vista wifi windows windows vista windows xp wireless
DOS/PDA/Other
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Operating Systems > DOS/PDA/Other >
BatchFile help.


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
aldistuck's Avatar
Junior Member with 1 posts.
 
Join Date: Dec 2006
12-Dec-2006, 07:03 AM #1
Question BatchFile help.
I was wondering if I could use "IF" statements to search and show specific information.

I would like to create a batch file that upon activation it asks me for a number and upon entering that number it displays information.

example:

I type 123456.
the batch file looks within itself to find a "IF" statement that says something like IF=123456 then show the following information. Ofcourse if the number isnt the right one I would like it not to show the information.

Is this possible, and if so can create one large batch file with tons of "IF" statements like this?

If possible could someone make me a working example because Im having a hard time getting it to work.

basically what I want is after typing the command for it to ask me to enter the number then after I enter the number have it show some information about that number.

Then have it stay on screen until I exit or press any key.

Thank You.
JohnWill's Avatar
Computer Specs
Moderator with 78,772 posts.
 
Join Date: Oct 2002
Location: South Eastern PA, USA
Experience: Advanced age & experience
12-Dec-2006, 08:47 AM #2
While it may be possible to beat the primitive batch capability into doing this, I normally look to 3rd party tools to do this kind of stuff. I suspect you'll find the right stuff to do the trick right here: http://garbo.uwasa.fi/pc/batchutil.html
Alex Ethridge's Avatar
Distinguished Member with 5,363 posts.
 
Join Date: Apr 2000
Location: Birmingham, Alabama USA
Experience: 14 years of hard knocks
30-Dec-2006, 10:36 AM #3
I agree with John; but, just to give you some guidance on "IF":

::TEST.BAT
IF "%1"=="123456" GOTO START
IF NOT "%1"=="123456" GOTO EXIT
:START
place command lines to be executed here
:EXIT
EXIT

You would type TEST 123456 to run the batch--note the space between TEST and 123456.

NOTE: If you use letters as well as numbers in your 123456, it is case sensitive.
Squashman's Avatar
Distinguished Member with 12,689 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
31-Dec-2006, 06:14 PM #4
What exactly is the purpose of all the IF statements. Sound more like you would want to use a Menu with the Choice command.
Alex Ethridge's Avatar
Distinguished Member with 5,363 posts.
 
Join Date: Apr 2000
Location: Birmingham, Alabama USA
Experience: 14 years of hard knocks
31-Dec-2006, 09:57 PM #5
I use IF statemts in batch files to identify various USB flash drives; different drives for different purposes or different backups will have different identification files on them. That way, I don't have to make a lot of clicks to perform retetitive backups to various drives.

IF statements can also be used to identify which drive letter a certain flash drive is using. Example:

Title Locating NeckDrive
if exist F:\Neck.ID goto F
if exist G:\Neck.ID goto G
if exist H:\Neck.ID goto H
if exist I:\Neck.ID goto I
if exist J:\Neck.ID goto J
if exist K:\Neck.ID goto K
if exist L:\Neck.ID goto L
if exist M:\Neck.ID goto M
if exist N:\Neck.ID goto N
goto NoDrive
:NoDrive
cd\
cls
echo.
echo.
echo No NeckDrive Found
Title No NeckDrive Found
goto exit
:F
F:
CD\
goto Begin
:G
G:
CD\
goto Begin
:H
H:
CD\
goto Begin
:I
I:
CD\
goto Begin
:J
J:
CD\
goto Begin
:K
K:
CD\
goto Begin
:L
L:
CD\
goto Begin
:M
M:
CD\
goto Begin
:N
N:
CD\
goto Begin
:Begin
XXCopy "D:\AC\Netscape\Bookmarks.html" "\FirefoxPortable\Data\Profile\" /d /h /r /c /Y
XXCopy "\FirefoxPortable\Data\Profile\Bookmarks.html" "D:\AC\Netscape\" /d /h /r /c /Y
etc.
etc.
etc.
:Exit


I once had a file that was zipped with encryption. I wrote a batch file that would unzip it if you entered the correct code after typing the name of the batch file.
Example: I typed SEEFILE 4854496 If the parameter was anything but 4854496, the batch would abort with an "Incorrect Parameter" error message. The IF line would read something like this:
IF "%1"=="4854496" [commands]
IF NOT "%1"=="4854496" ECHO Incorrect Parameter
IF NOT "%1"=="4854496" ECHO EXIT


I have a program that will convert a batch file to a .EXE file. Doing that made the batch file unreadable so no one could open the batch and dee the code.
JohnWill's Avatar
Computer Specs
Moderator with 78,772 posts.
 
Join Date: Oct 2002
Location: South Eastern PA, USA
Experience: Advanced age & experience
01-Jan-2007, 12:29 PM #6
When I'm doing automation under Windows, I far prefer AutoIt. Why do it the hard way? AutoIt is free, powerful, and will generate an EXE file with the commands. It runs rings around batch files in capability and ease of use.
Alex Ethridge's Avatar
Distinguished Member with 5,363 posts.
 
Join Date: Apr 2000
Location: Birmingham, Alabama USA
Experience: 14 years of hard knocks
01-Jan-2007, 02:30 PM #7
The hard way? That's relative. It depends on what you already know.

XXCopy works like XCopy except it is much more configurable and powerful. It will do things XCopy can't.
Example: XXCopy C:\*.* C:\Storage /s /r /h /y /c Try that with XCopy and you'll get a 'cyclic copy' error.

XXCopy also uses an exclude list. You can exclude files in a certain path, files of a certain extension, any folder in any path and there is no limit on the size of the exclude file. Mine currently has hundreds of excludes in it. I use it to extract user-created data from a hard disk for backup before formatting or replacing the drive. It makes the saving of a few megs out of several gigabytes very easy.

It will also clone one disk to another or one folder to another. It can be configured to update only the files in the destination that exist at the source and not copy other files at the source. It can be configured to copy only the files at the source that do not exist at the destination.

Each program has its own capabilities and weaknesses.

AutoIt looks interesting, though. Thanks for the link.
JohnWill's Avatar
Computer Specs
Moderator with 78,772 posts.
 
Join Date: Oct 2002
Location: South Eastern PA, USA
Experience: Advanced age & experience
01-Jan-2007, 06:27 PM #8
XXCOPY isn't part of MS-DOS or Windows. Remember that mention of 3rd party applications?
Alex Ethridge's Avatar
Distinguished Member with 5,363 posts.
 
Join Date: Apr 2000
Location: Birmingham, Alabama USA
Experience: 14 years of hard knocks
03-Jan-2007, 06:46 AM #9
Quote:
Remember that mention of 3rd party applications?
What mention? AutoIt is a third-party app, too. I don't understand that.
Closed Thread

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.


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 help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


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:45 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.