Last active
September 7, 2020 22:44
-
-
Save jsta/a795c35f3a5092fbf86e8c94b1941331 to your computer and use it in GitHub Desktop.
Curate Dropbox - List file and folder sizes to identify deletion targets
This file contains hidden or 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(rdrop2) # devtools::install_github("karthik/rdrop2") | |
library(dplyr) | |
top_level_path <- function(x){ | |
stringr::str_extract(x, "^(.+?)(\\/)") | |
} | |
rdrop2::drop_auth() | |
file_list_raw <- drop_dir(recursive = TRUE) | |
# saveRDS(file_list_raw, "dropbox-file-listing_2020-09-07.rds") | |
# file_list_raw <- readRDS("dropbox-file-listing_2020-09-07.rds") | |
file_list <- file_list_raw %>% | |
dplyr::filter(.tag == "file") %>% | |
dplyr::mutate(size = size / 1000000, # convert from b to mb | |
shared_folder = case_when( | |
!is.na(parent_shared_folder_id) ~ TRUE, | |
TRUE ~ FALSE) | |
) %>% | |
dplyr::select(c("name", "size", "path_lower", "client_modified", | |
"shared_folder")) %>% | |
dplyr::arrange(desc(size)) %>% | |
dplyr::mutate(top_folder = top_level_path(path_lower)) %>% | |
data.frame() | |
file_list %>% | |
group_by(top_folder) %>% | |
summarise(size = sum(size)) %>% | |
arrange(desc(size)) %>% | |
data.frame() | |
# 2000 mb limit on free tier | |
sum(file_list$size) * 0.001 # mb to gb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment