I'm in high school and working on making a batch file that does this:
Navigate to windows directory
Look for a file named problem.txt
if it exists, rename it to problem.old and display this message: File has been found and renamed
if it does not exist, display this message: problem.txt is not found
and change the working directory to c:\users using a relative path
This is what I have so far, and i just can't get it to work, very frustrating since this is my first time doing DOS.
@echo off
cd \
cd windows
IF EXIST problem.txt (GOTO :true) ELSE GOTO :false
:TRUE
rename c:\problem.txt problem.old
echo File has been found and renamed
:False
echo problem.txt is not found
Batch IF ELSE commands help please
Moderator: DosItHelp
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
You need a goto :eof statement in your :true area or else the :false stuff will also execute.
Don't forget to make sure you're on the correct drive.
c:
cd \windows
-- or --
cd /d c:\windows
Of course, are you supposed to use the %windir% variable to determine the windows folder? Wouldn't make sense with the requirement of using a relative path.
For relative path, you're going to have to figure out how to use the ".." directory.
Don't forget to make sure you're on the correct drive.
c:
cd \windows
-- or --
cd /d c:\windows
Of course, are you supposed to use the %windir% variable to determine the windows folder? Wouldn't make sense with the requirement of using a relative path.
For relative path, you're going to have to figure out how to use the ".." directory.