diff options
-rw-r--r-- | lib/fs.lua | 40 |
1 files changed, 37 insertions, 3 deletions
@@ -51,10 +51,30 @@ function read_file_as_array ( path ) return f end +-- find all return characters and removes them, may get this from a browser +-- that is why didn't do file specific + +function dostounix ( a ) +local data = string.gsub(a, "\r", "") +return data + +end + +-- read a file without blank lines and commented lines + +function remove_blanks_comments ( path ) +local f = io.open(path) +local lines = {} +for line in f:lines() do +local c = string.match(line, "^$") or string.match(line, "^%#") +if c == nil then lines[#lines + 1] = line end +end +-- returns a table to iterate over without the blank or commented lines +return lines +end - - --- write a string to a file +-- write a string to a file !! MM-will replace file contents + function write_file ( path, str ) local file = io.open(path, "w") if ( file ) then @@ -63,6 +83,20 @@ function write_file ( path, str ) end end +-- this could do more than a line +-- fs.write_line_file ("filename", "Line1 \nLines2 \nLines3") + +function write_line_file ( path, str ) + local file = io.open(path) + if ( file) then + local c = file:read("*a") + file:close() + local d = (c .. "\n" .. str .. "\n") + -- include a friendly newline for EOF + fs.write_file(path,d) + end +end + -- iterator function for finding dir entries matching filespec (what) -- starting at where, or currentdir if not specified. |