Can someone throw me together a quick .bat file?

Daniel2807

Commendable
Sep 4, 2016
20
0
1,510
I need a .bat file to, for example, rename file1 to file2, and file2 to file1.
I have tried putting this into a bat file to no avail

@Echo ON
Ren d:\file1 file2
Ren d:\file2 file1

Can someone help please?
Thanks

 
Solution


You need another line in there:
Ren d:\file1 file3
Ren d:\file2 file1
Ren d:\file3 file2
I'm assuming you want to do more than 2 renames?

It's easier to do it manually for just 2 renames than creating a batch file for it.


navigate to the directory or put the directory in the command

rename D:\file1.txt file2.txt

ren or rename should work, don't forget an extension for the files.


Note if there is a space in the file name you must use quotations.

rename D:\"file 1.txt" "file 2.txt"
 


You need another line in there:
Ren d:\file1 file3
Ren d:\file2 file1
Ren d:\file3 file2
 
Solution
If you wanted to do more than one rename at the same time you need to use a wildcard "*"

rename *.rtf *.txt

This changes the extension of any RTF file in the directory to a txt file.


Or even

rename file*.txt awesomefile*.txt


renames all

file*.txt

file1.txt file2.txt ...

to

awesomefile1.txt awesomefile2.txt
 

TRENDING THREADS