Search code examples
c#batch-filefile-extensionfile-type

Batch Open different programs depending on location


Is there Batch code/c# for if say for example, I have a anime folder and a movies folder and I want to watch anime with program A and movies with Program B.
Is there a way I can get the same file type (.mkv/.avi/.mp4) to open with different programs depending on its folder/hard drive location?
I assume I will have to set all video file types to open this batch but I do not know the arguments to enter.
Thanks.


Solution

  • You could write a batch file that launches the appropriate application based on the folder, like so:

    IF /I "%~dp1"=="C:\anime\" programA.exe %*
    IF /I "%~dp1"=="C:\movie\" programB.exe %*    
    

    Then right-click on one of your files and choose Open With - Choose Default Program, then browse to the .bat file you just created. Make sure the checkbox "Always use the selected program to open this kind of file" is checked.

    From now on, you can simply double-click the file and the correct program will be launched.