R: get list of files but not of directories

file, list, r

Solution

Here's one possibility:

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("*.*")

Problem

In R how can I get a list of files in a folder, but not of the directories? I have tried using `dir()`, `list.files()`, `list.dirs()` with different options, but none of them seems to work.

Original source