Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Tips for Manipulating
Filesystem in Julia
Julia Taiwan 發起人 杜岳華
Print working directory
julia> pwd()
"C:Usersa504082002"
Change directory
julia> cd("D:")
julia> pwd()
"D:"
Make directory
 mkdir(path::AbstractString, mode::Unsigned=0o777)
 `mkdir`
 mkpath(path::AbstractString, mode::Unsigned...
copy
julia> cp("D:foo", "D:foo2")
move
julia> mv("D:foo", "D:foo3")
Remove file
julia> rm("D:foo3")
touch
julia> touch("D:foo2test")
Base.Filesystem.File(false,RawFD(-1))
Get basename
julia> dirname("/home/myuser")
"/home"
julia> basename("/home/myuser/example.jl")
"example.jl"
Join path
julia> joinpath("D:", "foo", "bar")
"D:foobar"
Split directory
julia> splitdir("/home/myuser")
("/home", "myuser")
Split drive
julia> splitdrive("D:foo2test")
("D:","foo2test")
Split extensions
julia> splitext("/home/myuser/example.jl")
("/home/myuser/example", ".jl")
julia> splitext("/home/myuser/...
Folder traversal
for (root, dirs, files) in walkdir(".")
println("Directories in $root")
for dir in dirs
println(joinpath(...
list segment
 `ls`
julia> readdir()
55-element Array{String,1}:
".atom“
".julia"
".julia_history"
".jupyter"
⋮
"Videos"
"...
File information
julia> f = open("D:opensource video.txt", "r")
IOStream(<file D:opensource video.txt>)
julia> status = st...
File information
 ctime(file)
 mtime(file)
 filemode(file)
 filesize(path...)
 uperm(file): owner permission
 gperm(...
symbolic link (捷徑)
 symlink(target::AbstractString, link::AbstractString)
 `ln –s <target> <link>`
 readlink(path::Abst...
Change owner or mode
 chown(path::AbstractString, owner::Integer,
group::Integer=-1)
 chmod(path::AbstractString, mode::...
temp
 tempname(): generate a unique temporary file path
 tempdir(): generate a unique temporary direcotry path
julia> te...
Make temp
 mktemp(parent=tempdir())
 mktempdir(parent=tempdir())
julia> mktemp()
("C:UsersA50408~1AppDataLocalTempjl_758...
Thank you
Upcoming SlideShare
Loading in …5
×

20171014 tips for manipulating filesystem in julia

441 views

Published on

Julia Taiwan 9th meetup

Published in: Technology
  • Be the first to comment

20171014 tips for manipulating filesystem in julia

  1. 1. Tips for Manipulating Filesystem in Julia Julia Taiwan 發起人 杜岳華
  2. 2. Print working directory julia> pwd() "C:Usersa504082002"
  3. 3. Change directory julia> cd("D:") julia> pwd() "D:"
  4. 4. Make directory  mkdir(path::AbstractString, mode::Unsigned=0o777)  `mkdir`  mkpath(path::AbstractString, mode::Unsigned=0o777)  `mkdir -p` julia> mkdir("foo")
  5. 5. copy julia> cp("D:foo", "D:foo2")
  6. 6. move julia> mv("D:foo", "D:foo3")
  7. 7. Remove file julia> rm("D:foo3")
  8. 8. touch julia> touch("D:foo2test") Base.Filesystem.File(false,RawFD(-1))
  9. 9. Get basename julia> dirname("/home/myuser") "/home" julia> basename("/home/myuser/example.jl") "example.jl"
  10. 10. Join path julia> joinpath("D:", "foo", "bar") "D:foobar"
  11. 11. Split directory julia> splitdir("/home/myuser") ("/home", "myuser")
  12. 12. Split drive julia> splitdrive("D:foo2test") ("D:","foo2test")
  13. 13. Split extensions julia> splitext("/home/myuser/example.jl") ("/home/myuser/example", ".jl") julia> splitext("/home/myuser/example") ("/home/myuser/example", "")
  14. 14. Folder traversal for (root, dirs, files) in walkdir(".") println("Directories in $root") for dir in dirs println(joinpath(root, dir)) end println("Files in $root") for file in files println(joinpath(root, file)) end end
  15. 15. list segment  `ls` julia> readdir() 55-element Array{String,1}: ".atom“ ".julia" ".julia_history" ".jupyter" ⋮ "Videos" "「開始」功能表"
  16. 16. File information julia> f = open("D:opensource video.txt", "r") IOStream(<file D:opensource video.txt>) julia> status = stat(f) StatStruct(mode=100666, size=65) julia> status. blksize blocks ctime device gid inode mode mtime nlink rdev size uid julia> status.ctime 1.488506439013989e9
  17. 17. File information  ctime(file)  mtime(file)  filemode(file)  filesize(path...)  uperm(file): owner permission  gperm(file): group permission  operm(file): other permission
  18. 18. symbolic link (捷徑)  symlink(target::AbstractString, link::AbstractString)  `ln –s <target> <link>`  readlink(path::AbstractString) -> AbstractString  the target location a symbolic link `path` points to
  19. 19. Change owner or mode  chown(path::AbstractString, owner::Integer, group::Integer=-1)  chmod(path::AbstractString, mode::Integer; recursive::Bool=false)
  20. 20. temp  tempname(): generate a unique temporary file path  tempdir(): generate a unique temporary direcotry path julia> tempname() "C:UsersA50408~1AppDataLocalTempjl_FA AC.tmp" julia> tempdir() "C:UsersA50408~1AppDataLocalTemp"
  21. 21. Make temp  mktemp(parent=tempdir())  mktempdir(parent=tempdir()) julia> mktemp() ("C:UsersA50408~1AppDataLocalTempjl_7586.tmp ",IOStream(<file C:UsersA50408~1AppDataLocalTempjl_7586.tmp>)) julia> mktempdir() "C:UsersA50408~1AppDataLocalTempjl_1A09.tmp"
  22. 22. Thank you

×