Usage
Code: Select all
[MeasurePathParser]
Measure=Script
ScriptFile=PathParser.lua
Input=C:\Path\To\File.txt
Output=OutputType
- Input - a pure value.
- InputVariable - the name of a variable which resolves to the filepath.
- InputMeasure - the name of a measure whose current value is the filepath.
As for Output, you can specify one of four types:
- Dir - the file directory, including trailing backslash (\).
- Name - the file name, not including extension.
- NameExt - the file name, including extension.
- Ext - the file extension.
Code: Select all
PROPERTIES = {
Input = '0';
InputVariable = '0';
InputMeasure = '0';
Output = '';
VariablePrefix = '';
}
function Initialize()
sInput = PROPERTIES.Input
sInputVariable = PROPERTIES.InputVariable
sInputMeasure = PROPERTIES.InputMeasure
sOutput = PROPERTIES.Output
sVariablePrefix = PROPERTIES.VariablePrefix
end
function Update()
if sInput ~= '0' then
sPath = sInput
elseif sInputVariable ~= '0' then
sPath = SKIN:GetVariable(sInputVariable)
elseif sInputMeasure ~= '0' then
msInput = SKIN:GetMeasure(sInputMeasure)
sPath = msInput:GetStringValue()
else
return 'Invalid input type.'
end
sDir, sName, sExt = string.match(sPath, "(.-)([^\\]-)%.([^%.]+)$")
sNameExt = sName..'.'..sExt
SKIN:Bang('!SetVariable "'..sVariablePrefix..'Dir" "'..sDir..'"')
SKIN:Bang('!SetVariable "'..sVariablePrefix..'Name" "'..sName..'"')
SKIN:Bang('!SetVariable "'..sVariablePrefix..'NameExt" "'..sNameExt..'"')
SKIN:Bang('!SetVariable "'..sVariablePrefix..'Ext" "'..sExt..'"')
if sOutput == 'Dir' then
return sDir
elseif sOutput == 'Name' then
return sName
elseif sOutput == 'NameExt' then
return sNameExt
elseif sOutput == 'Ext' then
return sExt
else
return 'Invalid output type.'
end
end