user596454
user596454

Reputation: 13

Alternate file names with a batch file

I would like to know if there is a better way of renaming two files and alternate the names within a batch file. I am currently using this method.

ren httpd.conf temp_httpd.conf 
if exist _httpd.conf (
ren _httpd.conf httpd.conf
ren temp_httpd.conf _httpd.conf
)else (
ren _httpd.conf httpd.conf
)

Upvotes: 1

Views: 196

Answers (1)

jeb
jeb

Reputation: 82247

In my opinion the way is ok, but the false-case can't work.
If the file _http.conf doesn't exists, you try to rename it to http.conf.

I would change it to

if exist _httpd.conf (
  ren httpd.conf temp_httpd.conf
  ren _httpd.conf httpd.conf
  ren temp_httpd.conf _httpd.conf
)

Upvotes: 1

Related Questions