How can I rename a file from a txt file with Windows bat file?

Viewed 42

I have a batch script that renames a file to input.mkv so it can be processed by a string of other commands in the bat file with a final file called ProcessedVideo.mkv. I capture the OG file name using "dir *.mkv /b>OG_FileName.txt" before being renamed.

How can I rename the final processed mkv file to the name captured in the OG_FileName.txt and maybe add "_Added-Text.mkv" as the last part of my Batch Script? (Adding text to the file name is not that important if it is too much trouble).

I really thought this would be easy but I'm defeated.

1 Answers

Here a file called my.bat has one line with the dos command to rename a file. I want to rename the file called toy.txt to an new filename called toy.text

The dos command is:   ren toy.txt toy.text

To make the file from the command prompt I typed:

 copy con my.bat
 ren toy.text toy.txt
 ^Z

Where ^Z is the Ctrl+z key which writes the file. Then Dos gave me the result: 1 file(s) copied.

To run the batch file I typed my -- or -- I could have typed my.bat

Update: it tested that with ren toy.txt toy.txt_Added-Text.mkv

and got a renamed file : 12/10/2020 11:01 18,245 toy.txt_Added-Text.mkv

Note: you could use copy instead of ren for example.

 copy toy.txt_Added-Text.mkv toy.txt

That gives me a new file copied from toy.txt_Added-Text.mkv --to--toy.txt

Related