It is currently April 25th, 2024, 11:03 am

parsing local files

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

parsing local files

Post by moshi »

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: 446
Joined: August 7th, 2012, 9:18 pm

Re: parsing local files

Post by thatsIch »

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