Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Open file, any file extension

If you have a question or need help, this is the place to be.
Post Reply
Xavier_WER
Posts: 4
Joined: Sat Jan 21, 2017 9:31 am

Open file, any file extension

Post by Xavier_WER »

Howdy

I'm trying to setup a scenario where a trigger will open a videofile in a specified directory.
The files will be named 001, 002, 003 etc. However the file extensions might differ. Might be a mpg, mkv, avi etc...

The standard videoplayer will be vlc.

Just running 'start application' -> C:\Video\001.mkv
runs just fine, but what I need is something like 'start application' -> C:\Video\001.*

I've looked around for a commandline fix, like running "start ... c:\video\001" but haven't really gotten that to work.
Some googling suggest I create a batch file for each video file, but I'd rather not use batch files, IT guys might have an issue with them.

Any suggestions would be appreciated!
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Open file, any file extension

Post by kgschlosser »

here is some pseudo code that will point you in the right direction.

what this does is.. you set the folder for it to look in.
and you provide it with the name of the file without the extension
it will grab all of the file names from inside of the folder. and compare the name you provided against what is in the folder.. if it finds a match it will create a full path for you to pass along to the video player

so if a file was found the output would be like so. and the double '\' thing is not a typo they have to be like that
'c:\\some_path\\001.mkv'

and if nothing is found then the result is None

Code: Select all

import os
PATH_TO_VIDEOS = 'c:\\some_path'
fileName = "001"

result = None
for f in os.listdir(PATH_TO_VIDEOS):
    if f.split(".")[0] == fileName:
        result = os.path.join(PATH_TO_VIDEOS, f)
        break
 print result 

so if you wanted to use this in conjunction with an action like the Run Application.
create a macro.. add a python script to the macro.
copy and paste the code into the python script
add the action Run Application
in the file or folder put the path to VLC
in the command line options field you would put {eg.result} and make sure the disable parsing is unchecked
add the event to trigger it


again this is all pseudo code I have not tested it..
but give it a shot and if you have a problem let me know.
If you like the work I have been doing then feel free to Image
Xavier_WER
Posts: 4
Joined: Sat Jan 21, 2017 9:31 am

Re: Open file, any file extension

Post by Xavier_WER »

Thanks alot for your reply, I managed to find a solution before reading your post.

import glob
import os
filenamelist = glob.glob('c:\\test\\001.*')
filenamestr = ''.join(filenamelist[0])
os.startfile(filenamestr)


Haven't scripted in python before but it did the trick.
Post Reply