locate files using the fs package

When I put my files in project folder, the following code works fine.

library(fs)
files <- fs::dir_ls(glob = "file_name_pattern*txt")

Suppose I put my files in the subfolder called data. How do I locate the files in the data folder?

Hello @budugulo,

I think

fs::dir_ls(path="./data",glob = "file_name_pattern*txt")

should work (?)

Thanks for the reply @HanOostdijk . Unfortunately, it is not working.

That is rather vague.
Please execute in each environment where you work (base R or markdown or ...) for both your base folder and the data folder

getwd() 
ls() 

and show us the results.

This post was flagged by the community and is temporarily hidden.

These four should work:

fs::dir_ls(glob = "data/file_name_pattern*txt", recurse = TRUE)

fs::dir_ls(path = "data", glob = "data/file_name_pattern*txt")
fs::dir_ls(path = "data", glob = "*/file_name_pattern*txt")

fs::dir_ls(path = "data", regex = "file_name_pattern*txt")
1 Like

@AlexisW Many thanks for solving my problem! Please note that the one with the regex argument is not working.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.