FilePathsBase.jl provides a type based API for working with filesystem paths. Please review the FilePathsBase docs for more info on working with the base filepath types. FilePaths.jl extends FilePathsBase to provide easier interoperability with the rest of the Julia ecosystem.
FilePaths.jl is registered, so you can to use Pkg.add
to install it.
julia> Pkg.add("FilePaths")
julia> using FilePaths; using FilePathsBase: /
Globbing files:
julia> using Glob
julia> glob("*test*.jl", p"test")
2-element Array{PosixPath,1}:
p"test/runtests.jl"
p"test/test_uri.jl"
URIParsing:
julia> using URIs
julia> URI(cwd() / p"test/runtests.jl")
URI("file:///Users/rory/repos/FilePaths.jl/test/runtests.jl")
Writing String
and AbstractPath
compatible code:
julia> FilePaths.@compat function myrelative(x::AbstractPath, y::AbstractPath)
return relative(x, y)
end
myrelative (generic function with 2 methods)
julia> FilePaths.@compat function myjoin(x::P, y::String)::P where P <: AbstractPath
return x / y
end
myjoin (generic function with 2 methods)
julia> myrelative(cwd(), home())
p"repos/FilePaths.jl"
julia> myrelative(pwd(), homedir())
p"repos/FilePaths.jl"
julia> myjoin(parent(cwd()), "FilePaths.jl")
p"/Users/rory/repos/FilePaths.jl"
julia> myjoin("/Users/rory/repos", "FilePaths.jl")
"/Users/rory/repos/FilePaths.jl"