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.
To list all files in a directory in R programming language we use list. files(). This function produces a list containing the names of files in the named directory. It returns a character vector containing the names of the files in the specified directories.
Basic R Syntax: The dir R function returns a character vector of file and/or folder names within a directory.
You can think of R as having a file explorer window open invisibly in the background. You can see the folder that's open at the moment by typing getwd() at the console. setwd() tells R to open a different folder instead. setwd('../') tells R to go up to a parent directory.
setdiff(list.files(), list.dirs(recursive = FALSE, full.names = FALSE))
will do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With