How do I remove the extension from a filename?

Here we show you how to remove the extension from a filename using a bit of lua scripting. A typical example of where you need this is when you need to send a media file name to an Omneon server for playout. The Helm file browser control gives you the filename complete with extension, but the server needs just the filename and doesn’t work when the extension is added.

So here we have a file browser looking at a folder on a video server

media_1354486924122.png

It returns the filename complete with the extension – in this case .mxf

and we have this Load button down here

media_1354487012004.png

This button takes the filename and tells the Video Server to load up the clip ready to play. Problem is the video server an Omneon in this case wants the filename without the .mxf extension. So here’s how we get rid of it.

Let’s look at the script for the Load button

media_1354487357457.png

1. it’s in lua. Don’t know what Lua is? Find out more at www.lua.org.

2. we use the helm.get function to put the selected file in the variable ‘clipname’.

3 we a lua standard library function ‘string.gsub’ to replace “.mxf” with “” (empty string) in ‘clipname’ removing the .mxf extension.

4) we use the helm.exec function to tell the video server to load the filename contained in the ‘clipname’ variable.

Simple.

By the way…. string.gsub can do a lot more – for example the “find’ string can be a pattern. So a better way to find any file extension would be something like this string.gsub(clipname, “[.]%w%w%w$”,””) . You can find out more at http://www.lua.org/manual/5.1/manual.html#5.4.1