Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Set the repository owner, name, and branch
- local owner = "DYankee"
- local repo = "LapOs"
- local path = "main"
- local baseUrl = "https://api.github.com/repos/" .. owner .. "/" .. repo .. "/contents/"
- -- Set the directory where you want to download the files
- local directory = "/LapOs/"
- -- Define a function to get all folders in folder
- local function get_folder_list(url)
- local url = "https://api.github.com/repos/" .. owner .. "/" .. repo .. "/contents/"
- local response = http.get(url)
- local contents = textutils.unserialiseJSON(response.readAll())
- local folders = {}
- --check for folders
- for i = 1, #contents, 1 do
- if contents[i].type == "dir" then
- folders[i] = {url = contents[i].url}
- folders[i]= {name = contents[i].name}
- end
- end
- return folders
- end
- -- Define a function to get all files in folder
- local function get_file_list(dir)
- local url = baseUrl .. dir
- local response = http.get(url)
- local contents = textutils.unserialiseJSON(response.readAll())
- local files = {}
- --check for folders
- for i = 1, #contents, 1 do
- if contents[i].type =="file" then
- files[i] = {url = contents[i].url}
- files[i] = {name = contents[i].name}
- end
- end
- return files
- end
- -- Define a function to download a file
- local function download_File(url, path)
- local content = http.get(url).readAll()
- local file = fs.open(path, "w")
- file.write(content)
- file.close()
- end
- -- Define a function to download folder contents
- local function download_folder(folder)
- local files = get_file_list(folder.name)
- for i = 1, #files, 1 do
- download_File(files[i].url, files[i].path)
- end
- end
- local folders = get_folder_list()
- for i = 1, #folders, 1 do
- download_folder(folders[i])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement