Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Search program 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
- 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
- ------------------
- --MAIN------------
- ------------------
- local tArgs = { ... }
- if #tArgs > 0 then
- if lookFor(tArgs[1]) then
- print("Path: /"..path)
- else
- print("File not found")
- end
- return
- end
- if term.isColor() then
- advanced = true
- end
- if advanced then
- term.setTextColour( colors.yellow )
- end
- local done = false
- while not done do
- num = math.random(1, 3)
- if num == 1 then
- print("What file are you looking for?")
- elseif num == 2 then
- print("What file are you searching for?")
- elseif num == 3 then
- print("Did you loose a file? I will find it.")
- end
- print("Type \"help\" for help.")
- if advanced then
- term.setTextColour( colors.orange )
- end
- input = read()
- if advanced then
- term.setTextColour( colors.yellow )
- end
- if input == "help" then
- if advanced then
- term.setTextColour( colors.lightGray )
- end
- print("<Required> [Optional]")
- print("Usage: <filename>[.filetype]")
- print("or in shell: search <filename>")
- if advanced then
- term.setTextColour( colors.yellow )
- end
- else
- done = true
- end
- end
- if lookFor(input) then
- print("Path: /"..path)
- else
- print("File not found")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement