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...
3 replies to this topic
#1
Posted 31 March 2015 - 12:14 AM
#2
Posted 31 March 2015 - 01:36 AM
there's a game thread for "find the bug in this code" problems. Please don't try to do clickbait titles in AaP.
#3
Posted 31 March 2015 - 02:15 AM
local tDirs = {"/"}
local matched = {}
local tArgs = {...}
while #tDirs > 0 do
for k, v in pairs( fs.list( table.remove( tDirs, 1 ) ) do
local fullPath = fs.combine( dir, v )
if fs.isDir( fullPath ) then
tDirs[ #tDirs + 1 ] = fullPath
else
local file = fs.open( fullPath, "r" )
if file.readAll():find( tArgs[ 1 ] ) then
matched[ #matched + 1 ] = fullPath
end
file.close()
end
end
end
for k, v in pairs( matched ) do
print( v )
sleep(0.1)
end
Does this count?
Edited by KingofGamesYami, 31 March 2015 - 02:16 AM.
#4
Posted 03 April 2015 - 11:53 PM
If it works in the real game, then yes.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











