DrBurlao

Computercraft LUA. File explorer v1.0 (ESP)

May 20th, 2023 (edited)
70
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | Gaming | 0 0
  1. -- Función para escanear directorios y obtener los archivos Lua con sus rutas y tamaños
  2. local function scanFiles(directory)
  3.     local luaFiles = {}
  4.     local files = fs.list(directory)
  5.     for _, file in ipairs(files) do
  6.         local path = fs.combine(directory, file)
  7.         if fs.isDir(path) then
  8.             scanFiles(path) -- Escanea subdirectorios recursivamente
  9.         elseif file:match("%.lua$") then
  10.             local size = fs.getSize(path)
  11.             table.insert(luaFiles, { path = path, size = size })
  12.         end
  13.     end
  14.     return luaFiles
  15. end
  16.  
  17. -- Función para mostrar un menú paginado
  18. local function showMenu(files, currentPage, pageSize)
  19.     local totalPages = math.ceil(#files / pageSize)
  20.     currentPage = math.max(1, math.min(currentPage, totalPages))
  21.  
  22.     term.clear()
  23.     term.setCursorPos(1, 1)
  24.     print("Explorador de archivos Lua")
  25.     print("--------------------------")
  26.  
  27.     local startIdx = (currentPage - 1) * pageSize + 1
  28.     local endIdx = math.min(startIdx + pageSize - 1, #files)
  29.  
  30.     for i = startIdx, endIdx do
  31.         local file = files[i]
  32.         print(i .. ". " .. file.path)
  33.         print("   Tamaño: " .. file.size .. " bytes")
  34.     end
  35.  
  36.     print("--------------------------")
  37.     print("Página " .. currentPage .. "/" .. totalPages)
  38. end
  39.  
  40. -- Función para ejecutar un archivo Lua en un shell diferente
  41. local function runFile(file)
  42.     if fs.exists(file) and not fs.isDir(file) then
  43.         shell.openTab(file)
  44.     else
  45.         print("El archivo no existe o es un directorio.")
  46.     end
  47. end
  48.  
  49. -- Programa principal
  50. local files = scanFiles("/")
  51. local currentPage = 1
  52. local pageSize = 10
  53. local running = true
  54.  
  55. while running do
  56.     showMenu(files, currentPage, pageSize)
  57.     print("0. Salir")
  58.     write("Selecciona un archivo para ejecutar (número de archivo o página): ")
  59.     local input = read()
  60.  
  61.     if input == "0" then
  62.         running = false
  63.     elseif tonumber(input) then
  64.         local fileIdx = tonumber(input)
  65.         if fileIdx >= 1 and fileIdx <= #files then
  66.             runFile(files[fileIdx].path)
  67.             write("Presiona cualquier tecla para continuar...")
  68.             read()
  69.         else
  70.             print("Índice de archivo inválido.")
  71.             sleep(2)
  72.         end
  73.     elseif input == "p" or input == "P" then
  74.         currentPage = currentPage - 1
  75.     elseif input == "n" or input == "N" then
  76.         currentPage = currentPage + 1
  77.     else
  78.         print("Entrada inválida. Inténtalo nuevamente.")
  79.         sleep(2)
  80.     end
  81. end
  82.  
Advertisement
Comments
  • DrBurlao
    2 years
    # text 0.20 KB | 0 0
    1. The code provided is a Lua script that contains several functions to scan directories and retrieve Lua files with their paths and sizes, display a paginated menu, and execute Lua files in a different shell.
Add Comment
Please, Sign In to add comment