Much, much faster...Yincognito wrote: ↑November 15th, 2020, 4:59 am Nice one liner without the need for a batch file. I'll keep this in mind for the more general purpose of checking if a file of any type exists. Just for reference - I'm sure it's trivial, but how would a Lua script for this look like? It'll be faster than the RunCommand variant, right?
skin:
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Variables]
[Lua]
Measure=Script
ScriptFile=Test.lua
Disabled=1
[MeasureCheckFile]
Measure=Calc
Formula=[&Lua:exists('#@#Images\lampoon.jpg')]
DynamicVariables=1
IfCondition=MeasureCheckFile=1
IfTrueAction=[!SetOption MeterExists Text "lampoon.jpg FOUND!"][!UpdateMeter *][!Redraw]
IfFalseAction=[!SetOption MeterExists Text "lampoon.jpg NOT FOUND!"][!UpdateMeter *][!Redraw]
[MeterExists]
Meter=String
FontSize=15
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Code: Select all
function exists(fileArg)
f=io.open(fileArg,'r')
if f~=nil then io.close(f) return 1 else return -1 end
end
In the Lua, you are simply opening the file, which creates a "file handle". If the file handle is nil, which is Lua'ese for "doesn't exist", then return -1, else return 1. Note that ~= is how you say "not equal to" in Lua.