How to obtain a list of directories within a directory, like list.files(), but instead “list.dirs()”

后端 未结 7 614
梦如初夏
梦如初夏 2021-01-30 12:14

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 director

7条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 12:54

    You mention that you don't want to shell out to a Linux/UNIX command but I assume its ok to shell out to a Windows command. In that case this would do it:

    shell("dir/ad/b", intern = TRUE)
    

    and this would do it recursively:

    shell("dir/ad/b/s", intern = TRUE)
    

    Normally I would prefer the platform independent solutions of others here but particularly for interactive use where you are just concerned with getting the answer as simply and directly as possible this may be less work.

提交回复
热议问题