Search engine across multiple disk drives?
#1
Posted 27 April 2015 - 04:36 AM
#2
Posted 27 April 2015 - 05:40 AM
The way I'd approach this would be to first take the result of fs.list("") (which returns a numerically indexed table containing the names of all the files and folders in the root of the drive), then start a loop that inspects every element in that table, removing them as it goes. When it encounters a folder, it'd fs.list() its contents and add the contents of the new table to the first. When it encounters a match for the search term, it'd add that to a third table, which is what it'd return when the first table finally emptied.
#3
Posted 27 April 2015 - 10:38 PM
Bomb Bloke, on 27 April 2015 - 05:40 AM, said:
Edited by Kangaroo2K1, 28 April 2015 - 12:30 AM.
#4
Posted 28 April 2015 - 12:33 AM
#5
Posted 28 April 2015 - 02:30 AM
#6
Posted 28 April 2015 - 06:22 AM
for i,v in pairs(fs.list(path)) do print(v) end
#8
#9
Posted 28 April 2015 - 11:52 AM
Kangaroo2K1, on 28 April 2015 - 11:42 AM, said:
Did you just want the names of the files or the paths too?
I have a script I use in my xPlore file manager (It will take some time to search through lots of items)
Edited by DannySMc, 28 April 2015 - 11:52 AM.
#10
Posted 28 April 2015 - 11:58 AM
function searchall() local function yieldFsList(startPath) local list = fs.list(startPath) for _, file in ipairs(list) do local path = fs.combine(startPath, file) if fs.isDir(path) then yieldFsList(path) else coroutine.yield(path, file) end end end return coroutine.wrap(function() yieldFsList(start or "/") end end results = {} for path, name in searchall() do table.insert(results[1], name) table.insert(results[2], path) sleep(0) end local output = fs.open("searchresults", "w") output.write(textutils.serialize(results)) output.close()
Try this, and it should generate a file for ALL the files in all disk drives...
Depending on speeds my emulator runs at 1000fps and searches the files at about 40 per second, even when taking out sleep otherwise it may error...
Edited by DannySMc, 28 April 2015 - 11:59 AM.
#11
Posted 28 April 2015 - 12:21 PM
#12
Posted 28 April 2015 - 08:31 PM
DannySMc, on 28 April 2015 - 11:58 AM, said:
function searchall() local function yieldFsList(startPath) local list = fs.list(startPath) for _, file in ipairs(list) do local path = fs.combine(startPath, file) if fs.isDir(path) then yieldFsList(path) else coroutine.yield(path, file) end end end return coroutine.wrap(function() yieldFsList(start or "/") end end results = {} for path, name in searchall() do table.insert(results[1], name) table.insert(results[2], path) sleep(0) end local output = fs.open("searchresults", "w") output.write(textutils.serialize(results)) output.close()
Try this, and it should generate a file for ALL the files in all disk drives...
Depending on speeds my emulator runs at 1000fps and searches the files at about 40 per second, even when taking out sleep otherwise it may error...
#13
Posted 28 April 2015 - 08:49 PM
local tArgs = {...} --# Need to grab your extra word function searchall(start) --#Need to have it passed here so that you can choose local function yieldFsList(startPath) local list = fs.list(startPath) for _, file in ipairs(list) do local path = fs.combine(startPath, file) if fs.isDir(path) then yieldFsList(path) else coroutine.yield(path, file) end end end return coroutine.wrap(function() yieldFsList(start or "/") end) --# Someone forgot a ) here. end results = {} for path, name in searchall(tArgs[1]) do --#Sending over your path table.insert(results[1], name) table.insert(results[2], path) sleep(0) end local output = fs.open("searchresults", "w") output.write(textutils.serialize(results)) output.close()That's about all I see being wrong
#14
Posted 28 April 2015 - 09:54 PM
Dragon53535, on 28 April 2015 - 08:49 PM, said:
local tArgs = {...} --# Need to grab your extra word function searchall(start) --#Need to have it passed here so that you can choose local function yieldFsList(startPath) local list = fs.list(startPath) for _, file in ipairs(list) do local path = fs.combine(startPath, file) if fs.isDir(path) then yieldFsList(path) else coroutine.yield(path, file) end end end return coroutine.wrap(function() yieldFsList(start or "/") end) --# Someone forgot a ) here. end results = {} for path, name in searchall(tArgs[1]) do --#Sending over your path table.insert(results[1], name) table.insert(results[2], path) sleep(0) end local output = fs.open("searchresults", "w") output.write(textutils.serialize(results)) output.close()That's about all I see being wrong
Edited by Kangaroo2K1, 28 April 2015 - 09:54 PM.
#15
Posted 29 April 2015 - 01:24 PM
Remove the "[1]" and "[2]" and it
But you could do this:
table.insert(results, 1, name) table.insert(results, 2, name)
Edited by Square789, 29 April 2015 - 01:26 PM.
#16
Posted 29 April 2015 - 01:55 PM
Square789, on 29 April 2015 - 01:24 PM, said:
Remove the "[1]" and "[2]" and it
But you could do this:
table.insert(results, 1, name) table.insert(results, 2, name)
Yeah he is using the file manager I made which contains the search function as I took it from that.
#17
Posted 29 April 2015 - 11:48 PM
local tArgs = {...} --# Need to grab your extra word function searchall(start) --#Need to have it passed here so that you can choose local function yieldFsList(startPath) local list = fs.list(startPath) for _, file in ipairs(list) do local path = fs.combine(startPath, file) if fs.isDir(path) then yieldFsList(path) else coroutine.yield(path, file) end end end return coroutine.wrap(function() yieldFsList(start or "/") end) --# Someone forgot a ) here. end local results = {} results[1] = {} results[2] = {} for path, name in searchall(tArgs[1]) do --#Sending over your path table.insert(results[1], name) table.insert(results[2], path) sleep(0) end local output = fs.open("searchresults", "w") output.write(textutils.serialize(results)) output.close()
There we go, I fixed it again
#18
Posted 30 April 2015 - 08:27 PM
Dragon53535, on 29 April 2015 - 11:48 PM, said:
local tArgs = {...} --# Need to grab your extra word function searchall(start) --#Need to have it passed here so that you can choose local function yieldFsList(startPath) local list = fs.list(startPath) for _, file in ipairs(list) do local path = fs.combine(startPath, file) if fs.isDir(path) then yieldFsList(path) else coroutine.yield(path, file) end end end return coroutine.wrap(function() yieldFsList(start or "/") end) --# Someone forgot a ) here. end local results = {} results[1] = {} results[2] = {} for path, name in searchall(tArgs[1]) do --#Sending over your path table.insert(results[1], name) table.insert(results[2], path) sleep(0) end local output = fs.open("searchresults", "w") output.write(textutils.serialize(results)) output.close()
There we go, I fixed it again
#19
Posted 01 May 2015 - 12:37 AM
Kangaroo2K1, on 30 April 2015 - 08:27 PM, said:
I'll edit this post when I finish it. Shouldn't be long.
local tArgs = {...} local modem = peripheral.wrap("right") local function findFile(fileName) local function recurFile(directory,searchTerm) for a,v in pairs(directory) do if fs.isDir(v) then local fnd = recurFile(fs.combine(directory,v),searchTerm) if fnd ~= nil then return fnd end elseif v == searchTerm then return {true,fs.combine(directory,v)} end end end for a,v in pairs(modem.getNamesRemote()) do if peripheral.getType(v) == "drive" then local found = recurFile(disk.getMountPath(v),fileName) if found ~= nil then return unpack(found) end end end end local found,path = findFile(tArgs[1]) if found then print(path) endMake sure you edit that modem part to whatever side your wired modem is on
Edited by Dragon53535, 01 May 2015 - 12:48 AM.
#20
Posted 01 May 2015 - 01:16 AM
Dragon53535, on 01 May 2015 - 12:37 AM, said:
Kangaroo2K1, on 30 April 2015 - 08:27 PM, said:
I'll edit this post when I finish it. Shouldn't be long.
local tArgs = {...} local modem = peripheral.wrap("right") local function findFile(fileName) local function recurFile(directory,searchTerm) for a,v in pairs(directory) do if fs.isDir(v) then local fnd = recurFile(fs.combine(directory,v),searchTerm) if fnd ~= nil then return fnd end elseif v == searchTerm then return {true,fs.combine(directory,v)} end end end for a,v in pairs(modem.getNamesRemote()) do if peripheral.getType(v) == "drive" then local found = recurFile(disk.getMountPath(v),fileName) if found ~= nil then return unpack(found) end end end end local found,path = findFile(tArgs[1]) if found then print(path) endMake sure you edit that modem part to whatever side your wired modem is on
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users