早,各位简友,今天分享julia语言的文件和文件夹相关基础函数剩余部分:
参考资料:主页 · Julia中文文档 (juliacn.com)
## 修改文件名:mv()
mv("mydata.xls", "number.data")
readdir()
# 6-element Array{String,1}:
# "Julia关于文件目录和路径的相关函数.jl"
# "hello.txt"
# "newdir01"
# "newdir02"
# "newdir03"
# "number.data"
## 判断文件是否在目录中
"number.data" in readdir()
# true
"mydata.xls" in readdir("./")
# false
## 复制文件:cp()
cp("number.data", "number.txt")
# 7-element Array{String,1}:
# "Julia关于文件目录和路径的相关函数.jl"
# "hello.txt"
# "newdir01"
# "newdir02"
# "newdir03"
# "number.data"
# "number.txt"
## 读取文件内容
read("number.txt")
# 4501-element Array{UInt8,1}:
# 0x01
# 0x00
# 0x00
# ⋮
# 0x00
# 0x09
# 0x09
## 创建符号链接:symlink()
symlink("./number.txt", "./newdir01/number_symlink.txt")
readdir("./newdir01/")
# 1-element Array{String,1}:
# "number_symlink.txt"
## 查看软连接文件:readlink()
readlink("./newdir01/number_symlink.txt")
# "./number.txt"
## 判断是否是符号链接:islink()
islink("./newdir01/number_symlink.txt")
# true
islink("./number.txt")
# false
## 创建空文件:touch()
touch("empty.file")
# 8-element Array{String,1}:
# "Julia关于文件目录和路径的相关函数.jl"
# "empty.file"
# "hello.txt"
# "newdir01"
# "newdir02"
# "newdir03"
# "number.data"
# "number.txt"
## 判断路径是否存在:ispath()
ispath(pwd())
# true
newpath = "/path/to/empty"
ispath(newpath)
# false
## 获取当前用户的home目录的绝对路径
homedir()
# "/Users/juliauser"
## 获取路径的文件名
basename(pwd())
# "File_Directory_and_Path"
## 获取路径的目录
dirname(pwd())
# "/Users/juliauser/Functions_Scripts_Codes_Pipelines/Julia_Codes"
## 路径的末端分割
splitdir(pwd())
# ("/Users/juliauser/Functions_Scripts_Codes_Pipelines/Julia_Codes", "File_Directory_and_Path")
## 路径的合成
new_path = joinpath("/home/myuser", "example.jl")
print(new_path)
# /home/myuser/example.jl
## 获取绝对路径
abspath("./newdir01")
# "/Users/juliauser/Functions_Scripts_Codes_Pipelines/Julia_Codes/File_Directory_and_Path/newdir01"