Solved Help customizing batch file for use with 3rd party software

January 14, 2016 at 20:43:27
Specs: Windows 7
Hi Everyone,

I am trying to use Watch 4 Folder with a custom batch file. For those that do not know, Watch 4 Folder monitors a folder and when an event occurs (such as adding a file, within the folder you selected to watch), it executes a .bat.
So, I need a batch file that will ask the user what he/she would like to name the file, then change the extension from .MKV to .MP4, then move the file to another folder.

I have been trying, but everything I do errors (I know very little about writing batch files, but I am learning! I managed to get the extension and move to work, but I am having issues with prompting the user and using that information to rename the file.

Thank you


See More: Help customizing batch file for use with 3rd party software

Report •

January 14, 2016 at 21:13:41
✔ Best Answer
Changing the file extension, in the way of just changing the extension "on the outside" while keeping the original one "on the inside", is easily doable with batch, however I suspect that you mean converting, which to my knowledge cannot be done with plain batch.

To move a file, use the MOVE command. To view the help for the command, enter move /? in CMD.

To prompt the user, and "change" the file type you can do:

set /p fileName="Enter file name: "
ren "originalFileName.mkv" "%fileName%.mp4"

Keep in mind that the above will just change the extension, not convert the file, so it'll still be an .MKV file on the inside.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)

Report •

January 15, 2016 at 00:18:41
Hi RainBawZ,

I saw a post on the Kodi Forums, which was the best way to convert MKV to MP4 with minimal loss in quality. Come to find out, MKV and MP4 are what they called containers. The video and audio will play regardless of either extension, but MKV might have other features such as subtitles and chapters that may not work with MP4. MP4 is supported on more devices than MKV. I already tested changing the extension and it worked, which led me to my next task of automation. I am setting up this HTPC for my brother and this computer is going to be a media hub that can stream throughout the network, but he wanted to be able to rip the DVDs he owns so his 4 kids don't ruin them. Since this isn't a typically computer and will be used with a bluetooth remote controller, I am trying to make it extremely simple and automated. I tried your script plus I added the move aspect to it and it didn't work. I don't know much, but is there something else missing? I keep dropping the MKV in a temp folder called I:/Temp, but I do not believe it is relevant since Watch 4 Folder (W4F) monitors the folder, the second the file is dropped in there W4F executes the script, but the file does not move and also is prompting me twice to enter a name for the file. Here is the script I am using.

set /p fileName="Enter file name: "
ren "originalFileName.mkv" "%fileName%.mp4"
move I:\HTPC Media\DVDs

Thank you!


Report •

January 15, 2016 at 02:08:54
Nothing gets moved because you are not specifying anything for the command to move.

Try this (Replace C:\W4F\ with the path to the location where your W4F folder is):

move "C:\W4F\%filename%.mp4" "I:\HTPC Media\DVDs"

The only reason I can think of when it comes to prompting twice would be that W4F executes the script twice, probably due to the script itself performing actions inside the folder.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)

message edited by RainBawZ

Report •

Related Solutions

January 15, 2016 at 21:45:51
I think we are getting close! It still isn't working and I tried running the script one line at a time. I received an error on the second line,

"The system cannot find the file specified."

I also ran all of the script at once and the reply was

"enter file name:"ren "Frozen.mkv" "frozen.mp4" move "I:\temp\frozen.mp4" "I:\HTPC Media\DVDsFrozen

This is the script I am using.

set /p fileName="Enter file name:"
ren "%fileName%.mkv" "%fileName%.mp4"
move "I:\temp\%filename%.mp4" "I:\HTPC Media\DVDs\"

Neither the file extension or name are changing, when the batch file runs. It is prompting me to enter a name, but after I press enter a few more lines pop-up and then it closes in a blink of an eye.

I still haven't figured out why the batch file is being executed twice. It shows in W4F's log that it is being ran twice, so I am going to try and figure that out. I deleted recreated the parameters of the monitoring, but that didn't change anything.

Thank you


Report •

January 15, 2016 at 21:56:57
Well, I just came across this foot note in the user guide for W4F.

"Notice: some computer systems and configuration may trigger two events when selecting File Create event with large files."

Considering I am working with a 700+MB file, I am not surprised.

Report •

January 15, 2016 at 22:25:33
The error message suggests that either the REN or MOVE command fails to find the file to rename/move. Remember to include the path to the file you want to rename, or that the script is running in the same directory as the movie files.

In your case it would probably be

ren "I:\temp\%fileName%.mkv" "%fileName%.mp4"

You could add a

timeout /t 5 > nul

to make it wait for a bit before closing, so you get to read potential error messages before it closes.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)

Report •

January 17, 2016 at 00:05:48
Alright, I got it working after several hours on the internet. Below is the working batch file. We almost had it, I kept getting a syntax error and also file not found. Below is the finished script. I also had to place the batch file in the same folder that is being monitored.

@echo off
set /p answer= Enter file name:
ren *.mkv "%answer%.mp4"
move I:\temp\*.mp4 "I:\HTPC Media\DVDs\"
echo on

Thank you for your help


Report •

Ask Question