• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

rofinn/FilePathsBase.jl: Filesystem path types in julia

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

rofinn/FilePathsBase.jl

开源软件地址:

https://github.com/rofinn/FilePathsBase.jl

开源编程语言:

Julia 100.0%

开源软件介绍:

FilePathsBase.jl

Build Status codecov.io

FilePathsBase.jl provides a type based approach to working with filesystem paths in julia.

Intallation

FilePathsBase.jl is registered, so you can to use Pkg.add to install it.

julia> Pkg.add("FilePathsBase")

Getting Started

Here are some common operations that you may want to perform with file paths.

#=
NOTE: We're loading our `/` operator for path concatenation into the currect scope, but non-path division operations will still fallback to the base behaviour.
=#
julia> using FilePathsBase; using FilePathsBase: /

julia> cwd()
p"/Users/rory/repos/FilePathsBase.jl"

julia> walkpath(cwd() / "docs") |> collect
23-element Array{Any,1}:
 p"/Users/rory/repos/FilePathsBase.jl/docs/.DS_Store"
 p"/Users/rory/repos/FilePathsBase.jl/docs/Manifest.toml"
 p"/Users/rory/repos/FilePathsBase.jl/docs/Project.toml"
 p"/Users/rory/repos/FilePathsBase.jl/docs/build"
 p"/Users/rory/repos/FilePathsBase.jl/docs/build/api.html"
 p"/Users/rory/repos/FilePathsBase.jl/docs/build/assets"
 p"/Users/rory/repos/FilePathsBase.jl/docs/build/assets/arrow.svg"
 p"/Users/rory/repos/FilePathsBase.jl/docs/build/assets/documenter.css"
 ...

julia> stat(p"docs/src/index.md")
Status(
  device = 16777223,
  inode = 32240108,
  mode = -rw-r--r--,
  nlink = 1,
  uid = 501 (rory),
  gid = 20 (staff),
  rdev = 0,
  size = 2028 (2.0K),
  blksize = 4096 (4.0K),
  blocks = 8,
  mtime = 2020-04-20T17:20:38.612,
  ctime = 2020-04-20T17:20:38.612,
)

julia> relative(p"docs/src/index.md", p"src/")
p"../docs/src/index.md"

julia> normalize(p"src/../docs/src/index.md")
p"docs/src/index.md"

julia> absolute(p"docs/src/index.md")
p"/Users/rory/repos/FilePathsBase.jl/docs/src/index.md"

julia> islink(p"docs/src/index.md")
true

julia> canonicalize(p"docs/src/index.md")
p"/Users/rory/repos/FilePathsBase.jl/README.md"

julia> parents(p"./docs/src")
2-element Array{PosixPath,1}:
 p"."
 p"./docs"

julia> parents(absolute(p"./docs/src"))
6-element Array{PosixPath,1}:
 p"/"
 p"/Users"
 p"/Users/rory"
 p"/Users/rory/repos"
 p"/Users/rory/repos/FilePathsBase.jl"
 p"/Users/rory/repos/FilePathsBase.jl/docs"

julia> absolute(p"./docs/src")[1:end-1]
("Users", "rory", "repos", "FilePathsBase.jl", "docs")

julia> tmpfp = mktempdir(SystemPath)
p"/var/folders/vz/zx_0gsp9291dhv049t_nx37r0000gn/T/jl_1GCBFT"

julia> sync(p"/Users/rory/repos/FilePathsBase.jl/docs", tmpfp / "docs")
p"/var/folders/vz/zx_0gsp9291dhv049t_nx37r0000gn/T/jl_1GCBFT/docs"

julia> exists(tmpfp / "docs" / "make.jl")
true

julia> m = mode(tmpfp / "docs" / "make.jl")
Mode("-rw-r--r--")

julia> m - readable(:ALL)
Mode("--w-------")

julia> m + executable(:ALL)
Mode("-rwxr-xr-x")

julia> chmod(tmpfp / "docs" / "make.jl", "+x")
"/var/folders/vz/zx_0gsp9291dhv049t_nx37r0000gn/T/jl_1GCBFT/docs/make.jl"

julia> mode(tmpfp / "docs" / "make.jl")
Mode("-rwxr-xr-x")

# Count LOC
julia> mapreduce(+, walkpath(cwd() / "src")) do x
           extension(x) == "jl" ? count("\n", read(x, String)) : 0
       end
3020

# Concatenate multiple files.
julia> str = mapreduce(*, walkpath(tmpfp / "docs" / "src")) do x
           read(x, String)
       end
"# API\n\nAll the standard methods for working with paths in base julia exist in the FilePathsBase.jl. The following describes the rough mapping of method names. Use `?` at the REPL to get the documentation and arguments as they may be different than the base implementations.\n\n..."

# Could also write the result to a file with `write(newfile, str)`)

julia> rm(tmpfp; recursive=true)

julia> exists(tmpfp)
false

# Loading code from paths (e.g., S3Path)
julia> FilePathsBase.@__INCLUDE__()

julia> include(p"test/testpkg.jl")
Main.TestPkg



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap