Skip to content

Commit

Permalink
exclude hidden folders
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed Apr 24, 2024
1 parent 83562f8 commit 4cedc15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# findInFiles 0.5.0

* Files without base name (such as `.gitignore`) were excluded from the search.
This is no longer the case.

* Hidden folders were not excluded from the search when running a recursive
search (i.e. `depth` is `NULL` or a negative integer). Now they are always
excluded.

* The argument `ext` of the `findInFiles` function has been renamed to
`extensions` and it can be a vector of file extensions now.

Expand Down
9 changes: 7 additions & 2 deletions R/grepInFiles.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
getFiles <- function(extensions, depth){
stopifnot(isPositiveInteger(depth))
extensions <- do.call(c, lapply(extensions, function(ext) {
paste0(c(".", "*."), ext)
}))
wildcards <- do.call(c, lapply(extensions, function(ext) {
Reduce(
file.path, x = rep("*", depth), init = paste0("*.", ext),
file.path, x = rep("*", depth), init = ext,
right = TRUE, accumulate = TRUE
)
}))
Expand Down Expand Up @@ -99,7 +102,9 @@ grepInFiles <- function(
suppressWarnings(system2(
command,
args = c(
paste0("--include=\\*\\.", ext), opts, "-r", "-e", shQuote(pattern)
paste0("--include=\\*\\.", ext),
paste0("--exclude-dir=", shQuote(".*")),
opts, "-r", "-e", shQuote(pattern)
),
stdout = TRUE, stderr = TRUE
))
Expand Down

0 comments on commit 4cedc15

Please sign in to comment.