boB Rudis
6 years ago
8 changed files with 102 additions and 38 deletions
@ -0,0 +1,59 @@ |
|||
.s_unlink <- purrr::safely(unlink) |
|||
|
|||
#' Find and optionally remove `.DS_Store` files on a locally-accessible filesystem |
|||
#' |
|||
#' Provide a starting point, recursion option (similar to [list.files()]) & |
|||
#' whether or not to remove any `.DS_Store` files found and |
|||
#' get back a data frame of full paths to any `.DS_Store` files that exist |
|||
#' or were removed. The removal success status (if `remove` is `TRUE` will be added |
|||
#' as a column to the data frame).\cr\cr |
|||
#' If no `.DS_Store` files were found, an empty data frame is returned. |
|||
#' |
|||
#' @md |
|||
#' @param path a character vector of full path names; the default corresponds to |
|||
#' the working directory, [getwd()]. Tilde expansion (see [path.expand()]) |
|||
#' is performed. Missing values will be ignored. |
|||
#' @param recursive logical. Should the listing recurse into directories? Default is `FALSE`. |
|||
#' @param remove if `TRUE` the function will attempt to [unlink()] any `.DS_Store` |
|||
#' files found. Permissions issue may cause this option to fail to delete |
|||
#' found `.DS_Store` files. Default: `FALSE` |
|||
#' @export |
|||
find_dsstore <- function(path = ".", recursive = FALSE, remove = FALSE) { |
|||
|
|||
list.files( |
|||
path = path, |
|||
pattern = "\\.DS_Store", |
|||
all.files = TRUE, |
|||
full.names = TRUE, |
|||
recursive = recursive |
|||
) -> fils |
|||
|
|||
if (length(fils) > 0) { |
|||
|
|||
data.frame( |
|||
path = fils, |
|||
stringsAsFactors=FALSE |
|||
) -> ret |
|||
|
|||
if (remove) { |
|||
|
|||
purrr::map_lgl(fils, ~{ |
|||
|
|||
res <- .s_unlink(.x, force = TRUE) |
|||
if (is.null(res$result)) return(FALSE) |
|||
return(res$result == 0) |
|||
|
|||
}) -> rm_status |
|||
|
|||
ret$removed <- rm_status |
|||
} |
|||
|
|||
} else { |
|||
ret <- data.frame(stringsAsFactors=FALSE) |
|||
} |
|||
|
|||
class(ret) <- c("tbl_df", "tbl", "data.frame") |
|||
|
|||
ret |
|||
|
|||
} |
@ -0,0 +1,27 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/find-dsstore.R |
|||
\name{find_dsstore} |
|||
\alias{find_dsstore} |
|||
\title{Find and optionally remove \code{.DS_Store} files on a locally-accessible filesystem} |
|||
\usage{ |
|||
find_dsstore(path = ".", recursive = FALSE, remove = FALSE) |
|||
} |
|||
\arguments{ |
|||
\item{path}{a character vector of full path names; the default corresponds to |
|||
the working directory, \code{\link[=getwd]{getwd()}}. Tilde expansion (see \code{\link[=path.expand]{path.expand()}}) |
|||
is performed. Missing values will be ignored.} |
|||
|
|||
\item{recursive}{logical. Should the listing recurse into directories? Default is \code{FALSE}.} |
|||
|
|||
\item{remove}{if \code{TRUE} the function will attempt to \code{\link[=unlink]{unlink()}} any \code{.DS_Store} |
|||
files found. Permissions issue may cause this option to fail to delete |
|||
found \code{.DS_Store} files. Default: \code{FALSE}} |
|||
} |
|||
\description{ |
|||
Provide a starting point, recursion option (similar to \code{\link[=list.files]{list.files()}}) & |
|||
whether or not to remove any \code{.DS_Store} files found and |
|||
get back a data frame of full paths to any \code{.DS_Store} files that exist |
|||
or were removed. The removal success status (if \code{remove} is \code{TRUE} will be added |
|||
as a column to the data frame).\cr\cr |
|||
If no \code{.DS_Store} files were found, an empty data frame is returned. |
|||
} |
Loading…
Reference in new issue