Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Search API by svdragster
- local split = function(str, pat) local t = {} local fpat = "(.-)"..pat local last_end = 1 local s, e, cap = str:find(fpat, 1) while s do if s ~= 1 or cap ~= "" then table.insert(t,cap) end last_end = e+1 s, e, cap = str:find(fpat, last_end) end if last_end <= #str then cap = str:sub(last_end) table.insert(t, cap) end return t end
- debug = false
- found = false
- searchFileName = "nada"
- searchFileType = "sve"
- function getProgramType(path)
- programDir = split(path, "/")
- res = split(programDir[#programDir], "%.")
- programPath = path
- programName = res[1]
- programType = res[#res]
- if debug then
- term.setTextColour( colors.blue )
- print(programPath)
- print(programName)
- print(programType)
- term.setTextColour( colors.white )
- end
- end
- function check(path)
- if debug then
- print("check")
- end
- getProgramType(path)
- if debug then
- term.setTextColour( colors.green )
- print(programName)
- term.setTextColour( colors.orange )
- print(programType)
- term.setTextColour( colors.white )
- end
- if programName == searchFileName then
- if programType == searchFileType then
- found = true
- return
- end
- end
- end
- function readDir(dir)
- if debug then
- term.setTextColour( colors.red )
- print("Dir: "..dir)
- term.setTextColour( colors.white )
- end
- local dateien = fs.list(dir)
- for i = 1, #dateien do
- if debug then
- term.setTextColour( colors.red )
- print("Dir: "..dir)
- term.setTextColour( colors.white )
- print("readDir")
- end
- if found then
- return
- end
- local path = fs.combine(dir, dateien[i])
- if fs.isDir(path) then
- if (dateien[i] ~= "rom") then
- readDir(path)
- end
- end
- check(path)
- end
- end
- function lookFor(str)
- local res = split(str, "%.")
- searchFileName = res[1]
- searchFileType = res[#res]
- readDir("/")
- if found then
- return true
- else
- return false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment