-
Notifications
You must be signed in to change notification settings - Fork 0
/
lf.jl
39 lines (26 loc) · 948 Bytes
/
lf.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
Function creates an __Vector{String}__ of all files matching pattern. Made to imitate list.files() from R. Prints whole path.
# Additional Arguments:
- `path::String`: by default current working directory `pwd()`
- `pattern::Regex`: pattern for files to search for
- `sub::Bool`: Should subdirectories be searched to? By default `true`.
# Examples
```julia-repl
julia> lf(;pattern = Regex(".jl\\\$"))
```
"""
function lf(;path::String=pwd(), pattern::Regex=nothing, sub::Bool=true)
files = Vector{String}()
if sub
for cpath = walkdir(path)
x = joinpath.(cpath[1], cpath[3])
if !isempty(x)
idx = occursin.(pattern, cpath[3])
append!(files, x[idx] )
end
end
else
files = filter(x->occursin(pattern,x), first(walkdir(path))[3])
end
return(files)
end