Username
Username

Reputation: 3663

Get folder by regex in `list.files()`?

I want to get all *.txt files in the directory ../20180101_Folder.

My code:

theFiles <- list.files(
  path = "../*Folder",
  pattern = "*.txt",
  full.names = TRUE
)

But theFiles ends up being NULL. How do I make theFiles equal to a list of all .txt files in the specified directory?

Upvotes: 1

Views: 67

Answers (1)

G5W
G5W

Reputation: 37661

list.files will expand ~ in a path, but will not expand wild-cards like *. To use those you need

path=Sys.glob("../*Folder")

Upvotes: 5

Related Questions