VLC: adding media files to playlist via cmd using wildcards

What should I use instead of ??? ?

I am not aware of a native VLC option that would include only files of a certain type. Based on the command line documentation (also available with e.g. vlc -H), the closest option in VLC seems to be --ignore-filetypes which allows the exclusion of certain files by extension ex.:

vlc --ignore-filetypes=jpg,log,m3u,cue "C:\path to files" 

Note that as far as I can tell, --ignore-filetypes seems to only be applied when VLC initially starts. Running a second VLC call with --one-instance and --playlist-enqueue but different --ignore-filetypes extension parameters appeared to have no effect during testing in VLC 3.0.11 on Windows (July 2020).


Using A Script

With that said, building off the comment you placed on this answer, you may be able to achieve your goal with a script based around VLC's --one-instance and --playlist-enqueue options and e.g. Windows PowerShell:

ex. vlcq.ps1

# Use basic wildcard notation (ex. "*.mp3") to place
# matching file names from a directory into a VLC
# playlist.

# Set to ex. "C:\path to files\*.mp3" via the command-line
$playlist_path = $args[0]

# Turn ex. "C:\path to files\*.mp3" into ex. "C:\path to files\*"
$playlist_directory = Split-Path -Path $playlist_path
$playlist_directory = $playlist_directory + '\*'

# -Leaf returns the last item or container in a path
# (ex. "*.mp3")
$file_type = Split-Path -Path $playlist_path -Leaf

# Place any matching file names/paths into a $file_list
# $file_list = Get-ChildItem C:\path to files\* -Include *.mp3
$file_list = Get-ChildItem $playlist_directory -Include $file_type

# "Pre-load" VLC for (arguably) better intial playback, etc.
# Start-Process vlc -ArgumentList '--one-instance'
Start-Process "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" -ArgumentList '--one-instance'

foreach ($file in $file_list) {

    # Add quotes to $file output, since this may contain spaces.
    $quoted_file_path = '"' + $file + '"'

    # Queue up the item in the current VLC playlist.
    # Start-Process vlc -ArgumentList '--one-instance', '--playlist-enqueue', $quoted_file_path
    Start-Process "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" -ArgumentList '--one-instance', '--playlist-enqueue', $quoted_file_path

    # Add a delay between loading files to help avoid playlist
    # jumbling. May not be 100% effective.
    Start-Sleep -Seconds 2

    }

Where:

  • $args[0] is a PowerShell variable containing the first command line value after the script name (ex. a path\wildcard combination like C:\path to files\*.mp3).

  • \* is appended to $playlist_directory to ensure the -Include option of Get-ChildItem works correctly (without a final \*, an empty list may be produced).


Note that this script assumes a single playlist play-through. Unfortunately, looping didn't seem to work consistently for me.


Usage

Copy the script above and save it as ex. vlcq.ps1. You can use whatever file name you like but make certain to save it as a .ps1 (PowerShell script) file.

Assuming you opened a command window in the same directory as the saved .ps1 script (above), you could then load files into a VLC playlist with wildcards as follows ex.:

powershell -file .\vlcq.ps1 "C:\path to\*.mp3"

Note that you may need to enable PowerShell script execution before running the command above.

Helper Batch

If the command above is a little long to type, you can wrap it in a batch file e.g.:

ex. vlcq.bat

@ECHO Off

powershell -file "C:\path to\vlcq.ps1" %*

then simply run ex. vlcq "C:\path to\*.mp3" in the same directory as e.g. vlcq.bat. If you want ex. vlcq (a.k.a vlcq.bat) available anywhere from the command line, you can always place it in a folder in your Windows path.

Path Notes

  • The path to pass to the script for items in the current local directory would be .\ (ex. .\*.mp3).

  • *.mp3 is just an example. This syntax should work for any media type (i.e. *.ts). Note that this script has a potential side benefit in that it can queue up multiple images from a directory (which doesn't seem normally possible with just ex. vlc "C:\path\to\images").

  • If you provide a non-existent extension, etc. (i.e. you use *.mp3 with a directory that contains no .mp3 files), VLC will start (via the first Start-Process command), but no files will be added to the playlist.

  • You can use *.* but be aware that this will do exactly what it says. That is, it will load all the files in the directory (including any non-media files).

  • You can select items other than by extension with simple Windows regex (e.g. A*.mp3 will select .mp3 files starting with A).

  • When passing paths to the script above, some file paths that contain non-standard characters (ex. []) may not load correctly, even if they are generally not an issue in Windows.

Caveats

  • Remember that the Start-Process commands in the PowerShell script above need a valid path to VLC (assuming VLC isn't available from the command line as just vlc).

  • Beware of playlist jumbling. In short, calling VLC for each file (via ForEach and Start-Process) may result in some files being loaded out of order in the current playlist (compared to their order in the directory). Using a delay of e.g. 2 seconds after each call to load a file (via Start-Sleep -Seconds 2) seems to mostly alleviate this, but it may still be possible that some files could be loaded out of order (depending on VLC load times).

  • Though initial automatic playback shouldn't be affected, delaying file loading means that loading all the items in a directory may take some time (in the background) compared to e.g. simply opening a directory with ex. vlc "directory name" (which is nearly instantaneous). As a practical side effect, closing VLC before the script has loaded all these files will cause VLC to reopen and begin playing whichever file was last loaded by the script.

  • Regarding the powershell command, neither double-quotes around paths nor the -file option to powershell are technically needed if a path does not contain spaces, but paths with spaces will not work correctly without them (you will get a playlist full of essentially invalid items).

  • If you add any options to the basic powershell command above, -file should be the final option provided.


PowerShell References

  • Split-Path

  • Get-ChildItem

  • ForEach

  • Start-Process

  • Start-Sleep