It is currently October 21st, 2019, 4:08 am

parsing local files

Tips and Tricks from the Rainmeter Community
User avatar
moshi
Posts: 1851
Joined: November 13th, 2012, 9:53 pm

parsing local files

moshi » October 7th, 2013, 4:12 pm

just a hint:

when parsing local text files consider using the Quote plugin with RegExpSubstitute instead of the WebParser plugin.

this avoids any WebParser hiccups that might happen when you update often. it is also faster.
User avatar
thatsIch
Posts: 464
Joined: August 7th, 2012, 9:18 pm

Re: parsing local files

thatsIch » October 7th, 2013, 8:06 pm

or using Lua with the io library

Custom Code which can be included via dofile
€: it is not advised to use dofile if you are not familiar with the Rainmeter implementation of it, instead you can paste it into your normal code and use it like this (since dofile does the same)

Code: Select all

local FileReader do
	-- @param fileName string
	-- @return content string
	function FileReader(fileName)
		if not fileName then 
			print("IllegalArgumentEXception: " .. fileName .. " not a valid name.")
			return "" 
		end

		local fileHandle = io.open(fileName)
		if fileHandle == nil then
			io.close(fileHandle)
			print("IOEXception: " .. filePath .. " not found.")
			return ""
		else 
			local content = fileHandle:read('*all')
			io.close(fileHandle)

			return content
		end
	end
end

return FileReader