Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- File Deletion Program
- local function listFiles()
- -- Get the list of files in the /disk/packages/ directory
- local files = fs.list("/disk/packages/")
- local filteredFiles = {}
- -- Filter out the restricted files
- for _, file in ipairs(files) do
- if file ~= "package-installer" and file ~= "package-remover" and file ~= "package-editor" then
- table.insert(filteredFiles, file)
- end
- end
- return filteredFiles
- end
- local function displayMenu(files)
- print("Select a file to delete:")
- for i, file in ipairs(files) do
- print(i .. ". " .. file)
- end
- print("Enter the number of the file to delete, or 'q' to quit.")
- end
- local function deleteFile(file)
- -- Construct the full path
- local filePath = "/disk/packages/" .. file
- -- Delete the file
- fs.delete(filePath)
- print("Deleted: " .. file)
- end
- local function main()
- while true do
- local files = listFiles()
- if #files == 0 then
- print("No files available to delete.")
- break
- end
- displayMenu(files)
- -- Get user input
- local input = read()
- if input == 'q' then
- print("Exiting...")
- break
- end
- local choice = tonumber(input)
- if choice and choice >= 1 and choice <= #files then
- deleteFile(files[choice])
- else
- print("Invalid choice, please try again.")
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement