Jump to content




Search engine across multiple disk drives?

networking help

29 replies to this topic

#21 Dragon53535

  • Members
  • 971 posts
  • LocationIn the Matrix

Posted 01 May 2015 - 03:34 AM

Small oversight on my spot, didn't do it all correctly.
local tArgs = {...}
local modem = peripheral.wrap("right")
local function findFile(fileName)
  local function recurFile(directory,searchTerm)
	for a,v in pairs(fs.list(directory)) do --# Error was here, forgot fs.list
	  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) end


#22 Kangaroo2K1

  • Members
  • 13 posts
  • LocationEarth

Posted 02 May 2015 - 12:56 PM

View PostDragon53535, on 01 May 2015 - 03:34 AM, said:

Small oversight on my spot, didn't do it all correctly.
local tArgs = {...}
local modem = peripheral.wrap("right")
local function findFile(fileName)
  local function recurFile(directory,searchTerm)
	for a,v in pairs(fs.list(directory)) do --# Error was here, forgot fs.list
	  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) end
Attempted to search, but got this instead: "attempt to index ? (a nil value)"

#23 Dragon53535

  • Members
  • 971 posts
  • LocationIn the Matrix

Posted 02 May 2015 - 02:34 PM

Just to make sure, you're calling the program with an extra word right?

#24 Kangaroo2K1

  • Members
  • 13 posts
  • LocationEarth

Posted 02 May 2015 - 04:43 PM

View PostDragon53535, on 02 May 2015 - 02:34 PM, said:

Just to make sure, you're calling the program with an extra word right?
Yes, I type the command (search) and then the keyword (gameoflife, on one of my drives). So I enter search gameoflife. I've also tried searching for other keywords, but it doesn't work.

#25 Dragon53535

  • Members
  • 971 posts
  • LocationIn the Matrix

Posted 02 May 2015 - 05:13 PM

And the modem is on the right?

#26 Kangaroo2K1

  • Members
  • 13 posts
  • LocationEarth

Posted 02 May 2015 - 06:52 PM

View PostDragon53535, on 02 May 2015 - 05:13 PM, said:

And the modem is on the right?
Yes. If a red ring means on then yes, it is on.

#27 flaghacker

  • Members
  • 655 posts

Posted 02 May 2015 - 08:16 PM

Please post the full error, uncluding the line number.

#28 Kangaroo2K1

  • Members
  • 13 posts
  • LocationEarth

Posted 03 May 2015 - 02:27 AM

View Postflaghacker, on 02 May 2015 - 08:16 PM, said:

Please post the full error, uncluding the line number.
Played around with the code, ended up with a different result, what am I doing wrong here? https://www.dropbox..../snip3.JPG?dl=0

Edited by Kangaroo2K1, 03 May 2015 - 02:27 AM.


#29 Dragon53535

  • Members
  • 971 posts
  • LocationIn the Matrix

Posted 03 May 2015 - 10:57 PM

Ugh, it's not your fault. Silly getMountPath returns nil if you don't have a floppy in it. Give me a minute to fix it again with the correct line.
local tArgs = {...}
local modem = peripheral.wrap("right")
local function findFile(fileName)
  local function recurFile(directory,searchTerm)
	    for a,v in pairs(fs.list(directory)) do --# Error was here, forgot fs.list
		  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" and disk.hasData(v) then --# this should fix the problem
		  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) end

Edited by Dragon53535, 03 May 2015 - 10:58 PM.


#30 Kangaroo2K1

  • Members
  • 13 posts
  • LocationEarth

Posted 04 May 2015 - 03:01 AM

View PostDragon53535, on 03 May 2015 - 10:57 PM, said:

Ugh, it's not your fault. Silly getMountPath returns nil if you don't have a floppy in it. Give me a minute to fix it again with the correct line.
local tArgs = {...}
local modem = peripheral.wrap("right")
local function findFile(fileName)
  local function recurFile(directory,searchTerm)
		for a,v in pairs(fs.list(directory)) do --# Error was here, forgot fs.list
		  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" and disk.hasData(v) then --# this should fix the problem
		  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) end
Success! Thanks to all who helped with this, I do appreciate it. If need be, I could end up helping you, just not with coding (Building something cool). But anyway, thanks again! https://www.dropbox..../snip4.JPG?dl=0





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users