#' mp3_functions.R
#' functions to renumber, clean up mp3 file names
#' Given a dir, create fs:path ------------------
#'
#' @param dir (character).
#' @return fs:path.
#' @export
mp3_create_path <- function(dir="tmp") path <-fs::path(dir)
#' ----------------------------------------------
#' Given path, return tibble with file names (remove path prefix) in t$OLD
#'
#' @param path (fs:path).
#' @return tibble
#' @export
mp3_tibble <- function(path) {
# this returns tibble with <fs:path>
files <- fs::dir_ls(path)
# tibble, remove path
t <- tibble::tibble(OLD = fs::path_file(files))
}
#' ----------------------------------------------
#' Given a tibble, return cleaner tibble
#'
#' @param t tibble.
#' @return tibble.
#' @export
mp3_tibble_clean <- function (t) {
t %>% dplyr::mutate(clean1 = stringr::str_remove(OLD, "^[:digit:]{4,6}"))
}
#' Given a tibble, return tibble with proposed new name
#'
#' @param t tibble
#' @return tibble
#' @export
mp3_tibble_propose_new_name <- function(t) {
t %>% dplyr::mutate(new_id =
stringr::str_pad(dplyr::row_number(),side="left", width=5,"0")) %>%
dplyr::mutate(NEW = stringr::str_c(new_id,last_clean))
}
#' Given a tibble, do a TEST move on disk
#'
#' @param t tibble.
#' @param path (fs:path).
#' @return tibble
#' @export
mp3_tibble_move_files_TEST <- function(t,path) {
fs::file_move(path(p,t$OLD[[1]]), path(p,t$NEW[[1]]))
}
#' Rename (ie move) files on disk
#'
#' @param t Tibble of file names.
#' @param path fs:path to directory containing files.
#' @return Nothing.
#' @export
mp3_tibble_move_files <- function(t,path) {
fs::file_move(fs::path(p,t$OLD), fs::path(p,t$NEW))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.