Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.

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

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
:togetherNote the 'then' doesn't exist...
Have a good day,
Gérard from Paris, France

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

![]() |
windows protection error ...
|
used 17 inch cost
|

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