Skip to content

Instantly share code, notes, and snippets.

@elipousson
Created September 20, 2023 15:00
Show Gist options
  • Save elipousson/51c5b301a2063550cd3f11ed4fff2b13 to your computer and use it in GitHub Desktop.
Save elipousson/51c5b301a2063550cd3f11ed4fff2b13 to your computer and use it in GitHub Desktop.
library(Microsoft365R)
# site_url <- "fill in url"
site_files <- get_site_files(
site_url = site_url,
recurse = TRUE
)
files <- get_site_files(site_url)
get_site_files <- function(site_url,
drive_name = "Documents",
path = NULL,
recurse = FALSE) {
site <- get_sharepoint_site(
site_url = site_url
)
drive <- site$get_drive(
drive_name = drive_name
)
list_drive_files(drive, path, recurse)
}
list_drive_files <- function(drive,
path = sep,
full_names = TRUE,
sep = "/",
recurse = FALSE) {
drive_files <- drive$list_files(path = path, full_names = full_names)
if (!recurse) {
return(drive_files)
}
drive_file_list <- list(
drive_files
)
drive_dirs <- dplyr::filter(drive_files, isdir, size > 0)
if (nrow(drive_dirs) > 0) {
for (i in seq_along(drive_dirs[["name"]])) {
if ((path == "/") && full_names) {
path <- ""
} else {
path <- paste0(path, drive_dirs[["name"]][[i]], sep = sep)
}
print(path)
drive_file_list[[i + 1]] <- list_drive_files(
drive,
path = path,
recurse = recurse
)
}
}
vctrs::vec_rbind(drive_file_list)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment