How to obtain a list of directories within a direc

2020-05-14 13:17发布

This may be a very easy question for someone - I am able to use list.files() to obtain a list of files in a given directory, but if I want to get a list of directories, how would I do this? Is it somehow right in front of me as an option within list.files()?

Also, I'm using Windows, so if the answer is to shell out to some Linux/unix command, that won't work for me.

.NET for example has a Directory.GetFiles() method, and a separate Directory.GetDirectories() method, so I figured R would have an analogous pair. Thanks in advance.

标签: r directory
7条回答
萌系小妹纸
2楼-- · 2020-05-14 14:12

Just to update this thread:

I see that in the newer version of R (currently I'm using 2.5.1), there is now a list.dirs function included in the base install:

list.dirs implicitly has all.files = TRUE, and if recursive = TRUE, the answer includes path itself (provided it is a readable directory).

查看更多
登录 后发表回答