Open
Description
Ive run into errors using Base.walkdir
. These errors occur when I've tried to open directories that I don't have permissions for.
I modified walkdir()
bellow:
function walkdir(root; topdown=true, follow_symlinks=false, onerror=throw, skip = ['#','.'])
function _walkdir(chnl, root)
tryf(f, p) = try
if any(i->i==first(basename(p)),skip)
return
else
f(p)
end
catch err
isa(err, IOError) || rethrow()
try
onerror(err)
catch err2
close(chnl, err2)
end
return
end
content = tryf(readdir, root)
content === nothing && return
dirs = Vector{eltype(content)}()
files = Vector{eltype(content)}()
for name in content
path = joinpath(root, name)
# If we're not following symlinks, then treat all symlinks as files
if (!follow_symlinks && something(tryf(islink, path), true)) || !something(tryf(isdir, path), false)
push!(files, name)
else
push!(dirs, name)
end
end
if topdown
push!(chnl, (root, dirs, files))
end
for dir in dirs
_walkdir(chnl, joinpath(root, dir))
end
if !topdown
push!(chnl, (root, dirs, files))
end
nothing
end
return Channel{Tuple{String,Vector{String},Vector{String}}}(chnl -> _walkdir(chnl, root))
end
If this is not helpful then plz ignore.