Posted 31 March 2015 - 01:14 AM
Post your fixed code here and make sure that it actually prints searched files!
– advanced search function script
local args = {}
local searchstring = args[1] – the string we want to search.
local matchedfilecontents = {}
– Searches for the searchstring in each file.
local function filesearch(path)
local filelist = fs.list(path) – we need a table with all the files at the path of the directory.
for _, file in ipairs(filelist) do – enter a loop to search the filenames for the given search string.
if fs.exists(path.."/"..file) then
if not fs.isDir(path.."/"..file) then – we don't want to error if this is not a valid file.
local handle = fs.open(path.."/"..file, "r")
if string.find(handle.readAll(), searchstring) then – if we see a match then add the file to the search directory.
matchedfilecontents[#matchedfilecontents + 1] = path.."/"..file
end
else
filesearch(path.."/"..file)
end
end
end –End the loop
end
print("Found "..#matchedfilecontents.." matches for "..searchstring..".")
for k, v in ipairs(matchedfilecontents) do
print(v)
end
– End of script source.
The race starts in 3… 2…. 1….. Go! The clock is ticking…
– advanced search function script
local args = {}
local searchstring = args[1] – the string we want to search.
local matchedfilecontents = {}
– Searches for the searchstring in each file.
local function filesearch(path)
local filelist = fs.list(path) – we need a table with all the files at the path of the directory.
for _, file in ipairs(filelist) do – enter a loop to search the filenames for the given search string.
if fs.exists(path.."/"..file) then
if not fs.isDir(path.."/"..file) then – we don't want to error if this is not a valid file.
local handle = fs.open(path.."/"..file, "r")
if string.find(handle.readAll(), searchstring) then – if we see a match then add the file to the search directory.
matchedfilecontents[#matchedfilecontents + 1] = path.."/"..file
end
else
filesearch(path.."/"..file)
end
end
end –End the loop
end
print("Found "..#matchedfilecontents.." matches for "..searchstring..".")
for k, v in ipairs(matchedfilecontents) do
print(v)
end
– End of script source.
The race starts in 3… 2…. 1….. Go! The clock is ticking…