0

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.

user1264599
  • 33
  • 1
  • 5

1 Answers1

1

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

Winston
  • 38
  • 6
  • Thank you. I think you misunderstood my question. I want to rename a file from the text in a .txt file. So if I have a file called oldmovie.mkv and in a txt file called OGName.txt it says Star_Wars.mkv, then oldmovie.mkv would be named Star_Wars.mkv – user1264599 Sep 12 '22 at 22:11
  • 1
    Maybe this would help: https://stackoverflow.com/questions/23075953/batch-script-to-find-and-replace-a-string-in-text-file-without-creating-an-extra – Winston Sep 12 '22 at 22:28
  • Thank you. No.What I'm trying to do is renaming a file from the text inside of a txt file. my text.txt document, when opened says Star_Wars.mkv so my originalFile.mkv becomes Star_wars.mkv – user1264599 Sep 13 '22 at 10:27
  • You can find your answer in combining this answer and some from [this question](https://stackoverflow.com/questions/51300770/combining-key-value-pairs-in-bash-from-two-lists-in-text-files). Terminology often used for this is **dictionary** or text file or simply a list that serves as a **map** where for each line in text file there is equivalence. – Danilo Sep 22 '22 at 21:41
  • I found this and it looks like your answer... https://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir BUT THE BEST answer I've seen is this link found in the above link .. It is comprehensive with great examples ....... https://www.dostips.com/DtTipsStringManipulation.php#Snippets.Replace – Winston Sep 23 '22 at 22:17