Windows – File Association Based on File Type and Size

file associationpowerdvdvlc-media-playerwindows

I have many videos stored on my harddrive. The ones which are of dvd or lower quality (480p, max size 7GB), I would like to open using vlc. The ones which are HD quality (720p, 1080p, size greater than 7GB), I'd like to open using PowerDVD.

All files have the same extension (.mkv). Is it possible to program file association in Windows, such that it first looks at the file type (mkv in this case), and then also at the file size. It should automatically use either vlc or PowerDVD for mkv files, based on its size.

Please let me know if such a tweak is possible.

Best Answer

You'll have to associate the MKV extension with a batch file or PowerShell/VB script that in turn performs the file size check and invokes the appropriate application.

Here's how to do it with a batch file:

  1. Open regedit, navigate to HKEY_CLASSES_ROOT\.mkv and note the (Default) value. This is the ProgID. Let's assume it's mkvfile.

  2. Navigate to HKEY_CLASSES_ROOT\mkvfile\shell\open\command and modify the (Default) value to something like "D:\MKVSizeCheck.bat" "%1".

  3. Now create the D:\MKVSizeCheck.bat batch file with the following contents:

    if %~z1 leq 524288000 (
        start "" /max "C:\Program Files\VLC\VLC.exe" "%~1"
    ) else (
        start "" /max "C:\Program Files\PowerDVD\PowerDVD.exe" "%~1"
    )
    

Here's how to do it with VBScript:

  1. Same as above.

  2. Navigate to HKEY_CLASSES_ROOT\mkvfile\shell\open\command and modify the (Default) value to something like wscript //B "D:\MKVSizeCheck.vbs" "%1".

  3. Now create the D:\MKVSizeCheck.vbs file with the following contents:

    set objArgs = WScript.Arguments
    set objShell = WScript.CreateObject("WScript.Shell")
    set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
    if objFSO.GetFile(objArgs.Item(0)).Size <= 524288000 then
        objShell.Run """C:\Program Files\VLC\VLC.exe"" """ & objArgs.Item(0) & """", 3, false
    else
        objShell.Run """C:\Program Files\PowerDVD\PowerDVD.exe"" """ & objArgs.Item(0) & """", 3, false
    end if
    

Note #1: Modify the paths as required obviously. Also the code above sets 500MB (= 524288000 bytes) as the threshold so change that too as per your needs (very large values may be possible only in VBScript though).

Note #2: You can always use a utility like FileTypesMan to do steps 1-2 if you're unsure about manually editing the registry.

Note #3: Using a batch file will cause a console window to flash which might be irritating. Now this can be hidden using something like Hidden Start or VBScript, but why bother when it's better to directly use VBScript in the first place.

Related Question