R语言可以进行文件系统管理, 之前以为就Python比较编程的语言可以,其实R也可以,这样处理R的文件时,真方便,真开心。
## [1] "/workspace/projects/blog_181126/content/post/2017-12-21-r-manage-files"
文件内容是file A,\n表示换行
## [1] TRUE
## [1] TRUE
## [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [1] TRUE
## [1] TRUE TRUE
## [1] "A" "B"
unlink('tmp', recursive=FALSE) #如果文件夹tmp为空,删除文件夹tmp
unlink('tmp', recursive=TRUE) #删除文件夹tmp,如果其中有文件一并删除
file.remove('A','B','C') #移除三个文件## [1] TRUE TRUE TRUE
批量删除文件
如批量删除文件含有beta的文件。
dir() %>%
str_subset('beta') %>%
file.remove()
整理文档,计算视频时间
- R:
Extract File Information 创建时间等等
file.info(),不要加dir()间接通过size计算时间。
# getwd()C
'/Users/JiaxiangLi/Downloads/电影' %>%
list.files(full.names = T) %>%
file.info() %>%
# system(intern = TRUE) %>%
summarise(sum(size))/1000/1000/1000
full.names:
a logical value. If TRUE, the directory path is prepended to the file
names to give a relative file path. If FALSE, the file names (rather
than paths) are returned.
R删除其他格式的文件是不可以的
you probably have the file opened via another program.exe – amonk Jun 23 ’17 at 13:21
list.files() %>%
as_data_frame() %>%
filter(!value %in% str_subset(value, '.Rmd')) %>%
filter(value %in% str_subset(value, '.tmp')) %>%
.$value %>%
file.remove()
只看文件,不看文件夹
list.files()[!dir.exists(list.files())]