【发布时间】:2018-03-03 14:24:06
【问题描述】:
这一行给了我到文件的分层目录路径:
dirs<- as.data.frame(list.dirs(path = rootdir, full.names = F, recursive = T))
像这样:
"","list.dirs(path = rootdir, full.names = F, recursive = T)"
"1",""
"2","19"
"3","19/H"
"4","19/H/BA"
"5","19/H/BA/2016"
"6","19/H/BA/2016/11"
"7","19/H/BA/2016/11/10"
"8","19/H/BA/2016/11/10/0" # files are in here
"9","19/H/BA/2016/12"
"10","19/H/BA/2016/12/20"
"11","19/H/BA/2016/12/20/0" # files are in here
"12","19/H/BA/2017"
"13","19/H/BA/2017/1"
"14","19/H/BA/2017/1/19"
"15","19/H/BA/2017/1/19/0" # files are in here
"16","19/H/BA/2017/1/29"
"17","19/H/BA/2017/1/29/0" # files are in here
"18","19/H/BA/2017/3"
"19","19/H/BA/2017/3/20"
"20","19/H/BA/2017/3/20/0" # files are in here
但是我将如何编写代码来只给我文件的路径?即,
"19/H/BA/2016/11/10/0"
"19/H/BA/2016/12/20/0"
"19/H/BA/2017/1/19/0"
"19/H/BA/2017/1/29/0"
"19/H/BA/2017/3/20/0"
【问题讨论】:
-
您只需要包含任何文件的文件夹的路径吗?其余文件夹是空的吗?
-
@RonakShah:是的,其余文件夹都没有文件。
-
list.files仅返回那些存在的文件的路径,但我认为您需要将路径提高一级? -
@RonakShah:是的 - 我需要上一级以避免重复到同一文件夹的路径....