Computing.Net > Forums > Windows 95/98 > Batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file

Reply to Message Icon

Name: Jeremy
Date: September 16, 2003 at 10:53:57 Pacific
OS: W2K
CPU/Ram: 256
Comment:

I need to write a batch file that will contain an if then statement. I want the batchfile to look at the computers c drive and determin if there is a file present. If the file is preset I want it to do one thing , if not then another. Any advise is appreciated.




Sponsored Link
Ads by Google

Response Number 1
Name: safeTsurfa
Date: September 16, 2003 at 11:06:00 Pacific
Reply:

Easy peasy... I use this for checking floppy disks before writing the offline version of my web site. This is the entire batch file, so you can see how everything fits together. Tip: the weird symbols on the text lines create borders around the announcements when viewed in DOS. :)

I leave you to learn and do the hard work, by modifying the parts as needed:

@echo off
cls
echo.
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Welcome to safeTsurfa's º
echo º Safety Guide for Kids! º
echo ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo º This program writes the º
echo º guide onto a floppy disk. º
echo º º
echo º Please insert a blank º
echo º floppy disk in drive A: º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
pause
goto check

:check
attrib a:/s > c:\loadlog.txt
del c:\loadlog.txt
if errorlevel 1 goto goahead
goto livedisk

:livedisk
cls
echo.
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Files detected on drive A:! º
echo ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo º The disk in drive A: contains º
echo º files you may prefer to keep. º
echo º º
echo º Please make a selection from º
echo º the options below to proceed. º
echo º º
echo º ® OPTIONS ¯ º
echo º º
echo º A. View contents of the disk º
echo º B. Continue to use this disk º
echo º C. Replace with a blank disk º
echo º D. Cancel write Safety Guide º
echo ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo º WARNING!! º
echo º If you select B, all data º
echo º on the disk will be lost! º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
choice/n/c:abcd ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿMake your selection now (A, B, C or D)ÿ
if errorlevel 4 goto nowrite
if errorlevel 3 goto newdisk
if errorlevel 2 goto goahead
if errorlevel 1 goto content

:nowrite
cls
echo.
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Write Safety Guide aborted º
echo ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo º You may write the Safety º
echo º Guide at another time by º
echo º running this file again. º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
exit

:newdisk
cls
echo.
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Replace disk in drive A: º
echo ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo º Please insert a blank º
echo º floppy disk in drive A: º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
pause
goto check

:goahead
cls
echo.
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Writing safeTsurfa's Safety º
echo º Guide. Please be patient... º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
echo.
rawrite2 -f stsguide.img -d a -n
cls
echo.
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Safety Guide writing complete! º
echo ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo º You may now remove the disk from º
echo º drive A. Label with today's date º
echo º and "safeTsurfa's Safety Guide". º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
pause
cls
echo.
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Using safeTsurfa's Safety Guide º
echo ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo º To run, place the floppy disk in º
echo º drive A, and click the sTs link. º
echo º º
echo º You may create a shortcut to the º
echo º Guide by copying the link to the º
echo º Programs menu or on the desktop. º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
pause
cls
echo.
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Thanks for choosing to use º
echo º safeTsurfa's Safety Guide! º
echo º I hope you find it useful. º
echo º º
echo º You may use the link in the º
echo º guide to visit safeTsurfa's º
echo º site and check for updates. º
echo ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo º You may now close this window º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
exit

:content
cls
dir a: /s/p
echo.
pause
goto nextopt

:nextopt
cls
echo.
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º How do you wish to proceed? º
echo ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo º You have now seen a list of º
echo º the files found on drive A: º
echo º º
echo º Please make a selection from º
echo º the options below to proceed. º
echo º º
echo º ® OPTIONS ¯ º
echo º º
echo º A. Continue to use this disk º
echo º B. Replace with a blank disk º
echo º C. Cancel write Safety Guide º
echo ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo º WARNING!! º
echo º If you select A, all data º
echo º on the disk will be lost! º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
choice/n/c:abc ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿMake your selection now (A, B, or C)ÿ
if errorlevel 3 goto nowrite
if errorlevel 2 goto newdisk
if errorlevel 1 goto goahead


0

Response Number 2
Name: bert
Date: September 16, 2003 at 13:55:13 Pacific
Reply:

If exist c:\windows goto gotwin

:gotwin


0

Response Number 3
Name: Frenchie
Date: September 16, 2003 at 14:48:18 Pacific
Reply:


Hi Jeremy, safeTsurfa, bert, hi everyone,

bert gives the response, I go a bit farther:

If exist c:\windows\win.com goto OKfile
:nofile
rem the file has not been found
hogwash
goto together
:OKfile
rem the file has been found
waffle
:together

Note the 'then' doesn't exist...

Have a good day,
Gérard from Paris, France


0

Response Number 4
Name: Nathan
Date: September 16, 2003 at 17:16:49 Pacific
Reply:

wow you guys give some pritty weird responses. how but somethin like this
____________________________________________________________
@echo off
echo searching
if exist "C:\(file name here).(ext here) goto filefound
goto notfound


:filefound
echo file was found
::do stuff here
goto end

:notfound
echo file was not found.
goto end

:end
pause


0

Response Number 5
Name: Don Miller
Date: September 17, 2003 at 04:58:13 Pacific
Reply:

That'll do.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

windows protection error ... used 17 inch cost



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows 95/98 Forum Home


Sponsored links

Ads by Google


Results for: Batch file

how do you make a batch file use the "enter" key www.computing.net/answers/windows-95/how-do-you-make-a-batch-file-use-the-enter-key/34074.html

Batch File To Determine Exact OS www.computing.net/answers/windows-95/batch-file-to-determine-exact-os/149442.html

batch file problems www.computing.net/answers/windows-95/batch-file-problems/116856.html