windowspowershellbatch-filesendto

Simple "SendTo" script on Windows


I would like to create a simple script containing :

"C:\Users\Professional\NVEncC_5.24_x64\NVEncC64.exe" --codec h265 --preset quality --profile main10 --tier high -i "Project.mkv" -o "Project-Q27.mkv"

that i can reach by Right Click => SendTo.

I Understand that i need to name the file XXX.bat and paste it in SendTo folder.

But i don't know how to get the filename to dynamically add it to the script instead of "Project.mkv".

Can you help me ?

Thanks !

K.


Solution

  • A .bat file with the following should work.

    "C:\Users\Professional\NVEncC_5.24_x64\NVEncC64.exe" --codec h265 --preset quality --profile main10 --tier high -i "%~f1" -o "%~n1-Q27.mkv"
    
    pause
    

    I also added the pause so you'll be able to see what happens if it's quick but it can be removed.

    %~f1 is the argument for the file you've right clicked and used "SendTo" on (expanded to the full path). %~n1-Q27.mkv" is essentially the same as argument %~f1 but without the file extension and it adds -Q27.mkv to whatever the filename was.

    So if you right click/SendTo/yourbat.bat on a file called Funny.mkv the command (NVEncC64.exe) will be run on that file and output to a file called Funny-Q27.mkv.

    I suggest you take backups of your files before testing so that you do not overwrite any existing files by mistake.