Last active
June 14, 2023 07:06
-
-
Save CBSti/ae0c2921e7986b517db3e6f3e3a4d0ba to your computer and use it in GitHub Desktop.
R Function for recursive search of directories queried via the Microsoft365R package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(Microsoft365R) | |
library(tidyverse) | |
list_files_recursive <- function(folder_path) { | |
files <- drv$list_items(folder_path) %>% | |
mutate(path = folder_path, | |
checked = ifelse(isdir == F, T, F)) | |
while(any(files$checked == F)) { | |
for (id in files[!(files$checked), "id"]) { | |
print(id) | |
subfolder_path <- paste0(files[files$id == id, "path"], "/", files[files$id == id, "name"]) | |
files <- bind_rows(files, | |
drv$list_files(subfolder_path) %>% | |
mutate(path = subfolder_path, | |
checked = ifelse(isdir == F, T, F))) | |
files[files$id == id, "checked"] <- T | |
} | |
} | |
return(files) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment