R:获取文件列表但不获取目录 [英] R: get list of files but not of directories

查看:38
本文介绍了R:获取文件列表但不获取目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R中,如何获取文件夹中的文件列表,而不是目录的文件列表?

In R how can I get a list of files in a folder, but not of the directories?

我尝试将dir()list.files()list.dirs()与其他选项一起使用, 但它们似乎都不起作用.

I have tried using dir(), list.files(), list.dirs() with different options, but none of them seems to work.

推荐答案

这是一种可能性:

all.files <- list.files(rec=F)
all.files[!file.info(all.files)$isdir]

另一个选项(当然,带有扩展名的文件的模式并不通用):

Another option (pattern for files with extensions, not so universal, of course):

Sys.glob("*.*")

这篇关于R:获取文件列表但不获取目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆