Batch If (file exists)

Microsoft Windows xp professional w/serv...
November 19, 2009 at 12:12:03
Specs: Windows XP

I'm pretty new to batch program, but I've been asked at work to create a batch that renames one file, then renames another file to the name of the first file. Then the next time it runs, I'd like it to set the file names back to the original. I can get it to change one way, but I'm not sure about how to change it back.

What I was thinking was (in pseudo-code):
if (temp-test.txt exists)
rename test.txt --> training-test.txt
rename temp-test.txt --> test.txt
rename test.txt --> temp-test.txt
rename training-test.txt --> test.txt

Basically what I need to know is the best way to determine if test-temp.txt file exists

Thanks very much for your help.

See More: Batch If (file exists)

Report •

November 19, 2009 at 12:24:26
Nevermind, I figured it out (once I made the post, the related posts showed me how... for some reason I didn't see any of those threads before I posted)


Report •

November 19, 2009 at 12:34:06
@echo off
if exist temp-test.txt ( 
  ren test.txt training-test.txt
  ren temp-test.txt test.txt
) else (
  ren test.txt temp-test.txt
  ren training-test.txt test.txt
:: End_Of_Batch

Report •

Related Solutions

Ask Question