how to make a batch file to look for a file

April 7, 2011 at 19:20:41
Specs: Windows XP, 1gb
i want to make a batch file that looks for a file on a cd in my cd drive before continuing. so if it cant find the file it wont continue and will either close or do what ever else i tell it. like say if i wanted

@echo off
title test
color 0A
echo now searching cd drive for files
"this is where i need the code"
"if it finds the file goto FOUND"
"if the file wasnt there goto LOST"

sounds simple i would say.
but i have not figured out how to do it. i tried using the "if exist" command (i have used before) and it didnt work so i tried the CD command with the directory path i wanted but that didn't work either?

so basically i want it so that if it finds the file it continues if it doesnt it displays a error message


See More: how to make a batch file to look for a file

Report •


#1
April 8, 2011 at 00:54:46
Can you post your script, so experts can have a look at it.

Happy is ONE who says I am an OttoMAN.


Report •

#2
April 8, 2011 at 10:19:44
ok, go to where it says :4
then goto where it says
ECHO RC's Tools installed! >RC'sToolsDONOTOPEN.
i want to replace that to where it gets files off of a cd in the cd drive and copies them to the folder the batch file is being ran from.


@echo off
TITLE RC's Tools Installer
COLOR 0A
ECHO this installer will run you through the installation of RC's Tools
ECHO RC's tools is a freeware software and is not to be sold for a profit.
ECHO RC's tools will not damage your system if used right.
ECHO read the read.txt to see how to use RC's tools properly
ECHO if you did not read it then we will not be responsible for any damage done
ECHO to your computer/computers
ECHO press enter to begin installation process
pause
cls
:mainmenu
echo 1. Download Installation files
echo 2. Check for succesfull download
echo 3. enable read/write abilities
echo 4. Install RC's tools (run all other tasks except run automated install before running installation)
echo 5. run automated install (does not require you to be at the comptuer during install)
echo do the following in order or RC's Tools will nto be installed properly
echo you can use the automated install
echo to select a answer type 1,2,3,4,5, or 6
echo if you want to exit RC's tools installer type quit
set input=
set /p input=
if %input%==1 goto 1
if %input%==2 goto 2
if %input%==3 goto 3
if %input%==4 goto 4
if %input%==5 goto 5
if %input%==quit goto quit

:1
set _number=0
:start1
if %_number%==14842 goto end1
echo %_number%
cls
echo %_number%
set /a _number +=1
goto start1
:end1
echo %_number% out of %_number% were installed onto your computer succesfully
PING 127.0.0.1 -n 5 > nul
goto mainmenu

:2
echo checking for downloaded files... (this can take some time, ranging from 1 minute to 10 minutes)
PING 127.0.0.1 -n 60 > nul
echo all 14842 files were downloaded without errors and are located in there proper place.
PING 127.0.0.1 -n 5 > nul
cls
goto mainmenu

:3
ECHO enabling read/write file abilities
ECHO this is so the program can install the files without being blocked
PING 127.0.0.1 -n 5 > nul
cls
ECHO read/write abilities have been enabled for this program
ECHO they will be disabled after the program is installed
PING 127.0.0.1 -n 5 > nul
goto mainmenu

:4
ECHO installing RC's Tools onto your computer
PING 127.0.0.1 -n 300 > nul
ECHO RC's tools have been installed onto your computer and is now on your desktop
ECHO in a folder named RC's Tools DO NOT move this folder off the desktop
ECHO however you can move the shortcut to the desktop from the RC's tools folder
ECHO RC's Tools installed! >RC'sToolsDONOTOPEN.txt
PING 127.0.0.1 -n 10 > nul
goto mainmenu

:5
ECHO automated install could not be ran do to system error
ECHO please run the normal install step by step
ECHO run tasks 1 though 4
ECHO to install RC's Tools
PING 127.0.0.1 -n 5 > nul
goto mainmenu

:quit
exit


Report •

#3
April 9, 2011 at 03:28:16
1. if %_number%==14842 goto end1

Label "end1" does not exist, so it will give a error message and prob, quit the script.

---

Your question in your post "i want to make a batch file that looks for a file on a cd in my cd drive before continuing. so if it cant find the file it wont continue and will either close or do what ever else i tell it. like say if i wanted"

@echo off
if not exist P:\a\t\h\file.ext goto notfound
goto continue

:notfound
echo File not found..
pause
exit

:continue
echo DO YOUR THING HERE
pause

Happy is ONE who says I am an OttoMAN.


Report •

Related Solutions

#4
April 9, 2011 at 12:41:27
i was unable to get it to find the file i wanted on the cd, but i was able to get i to find it on a usb flash drive after editing the script a little, thanks

Report •

Ask Question