Trying to get an array of the names of all the pdf files in the current directory, so I wrote the below:
files = cd(readdir, pwd())
for f in files
if match(r"*.\.pdf", f) !== nothing # Or if occursin(r"*.\.pdf", f) == true
println(f)
end
end
But I got the below error:
PCRE compilation error: quantifier does not follow a repeatable item at offset 0
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] compile(::String, ::UInt32) at ./pcre.jl:104
[3] compile(::Regex) at ./regex.jl:69
[4] Regex(::String, ::UInt32, ::UInt32) at ./regex.jl:40
[5] Regex(::String) at ./regex.jl:65
[6] @r_str(::LineNumberNode, ::Module, ::Any) at ./regex.jl:103
Hard to say without more information. What is the output of readdir()?
Yes. filter applies the function (first argument) to every element of the collection (second argument) and returns a vector of all elements for which the function evaluated to true.
Hm, Glob.jl does support caseless operation for Glob.FilenameMatch, but I’m not sure how to use that with it’s glob() function. @jameson, can I pull you into this thread for some help?
Glob.jl also supports regexes, as shown in the README as usage 3, so this, for example, should match the rather unlikely path “./name.pdf/name.pDf/name.PdF”: