cmd, Open file in Command Prompt shell without knowing its extension

1.5k views Asked by At

I would like to run a file, in cmd without knowing the type (e.g. JPG, mp3, txt, mp4 and etc). I tried to use 'start' command, but start (as far I found) need to know the full name of the file (with extension) and which program it should use to run it (e.g. VLC, notepad, photo viewer). So, for example, instead of using C:\AI>start "VLC media player" "Bernard.avi" I want something like C:\AI>start "Bernard" to work similar.

2

There are 2 answers

0
J.Baoby On BEST ANSWER

If you are sure only one file has that filename you use a for loop to search for the file like this:

FOR %A IN ("C:\path\to\directory\filename.*") DO start %A 

In your example it would be:

FOR %A IN ("C:\AI\Bernard.*") DO start %A

You can put it in a batch-script:

@echo off
FOR %%A IN ("%~1.*") DO start %%A

and give the path to the filename without extension as argument (don't forget the surrounding double quotes).

If multiple files have that filename it will open them all.

0
miqe On

On linux terminal you could do something like this vlc Bernard.*,maybe you could try the * extension for windows.