'how change file name with batch file? [closed]
i have 2 file with name : file.txt and file1.txt Sometimes it is necessary to change the name of these 2 files for example file1.txt chnage to file.txt And conversely I'm doing this manually right now I want to create a batch file that we double-click on it to do this
Solution 1:[1]
set "dirname=?:\wherever\your files\reside"
:again
set "tempname=%random%.txt"
if exist "%dirname%\%tempname%" (goto again) else ECHO ren "%dirname%\file1.txt" "%tempname%"
ECHO ren "%dirname%\file.txt" "file1.txt"
ECHO ren "%dirname%\%tempname%" "file.txt"
where you assign your directory name to dirname.
The code will simply echo the commands required. Remove the echo keyword after verification to actually perform the name-swap.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Magoo |
