# 文件操作函数
Usage
file.create(..., showWarnings = TRUE)
file.exists(...)
file.remove(...)
file.rename(from, to)
file.append(file1, file2)
file.copy(from, to, overwrite = recursive, recursive = FALSE,
copy.mode = TRUE, copy.date = FALSE)
file.symlink(from, to)
file.link(from, to)
setwd("~/test")
dir= "/Users/test"
setwd(dir)
getwd()
# 文件位置
file <- file.path(dir,'tmp.txt')
# class(file) # character 文件路径位置
# 删除最后一个路径分隔符(如果有)之前的所有路径。
basename(file.path("","p1","p2","p3", c("file1", "file2")))
#获取文件所在路径
dirname (file.path("","p1","p2","p3", "filename"))
#查看当前目录的子目录
list.dirs()
list.files()
#查看当前目录的子目录和文件
dir()
# 查看指定目录的子目录和文件
dir(path = "test")
#查看当前目录的信息
file.info(".")
#检查目录或文件是否存在
file.exists("./other")
#判断是文件还是目录
file_test("-f", "abc")
file_test("-d", "abc")
# 创建目录
dir.create("abc")
#创建多级目录
dir.create("a/b/c", recursive=TRUE)
#创建空文件
file.create("abc.txt")
#删除文件或目录
unlink("abc")
#删除文件
file.remove("abc.txt")
#文件或者目录重命名
file.rename("abc", "def")
#复制文件
file.copy(from, to)
# 调用系统命令
system("tree") #查看目录结构