R bind for multiple files

Hi everyone,

I have 3 folders in C:drive each folder consists of 3 csv files so total I got 9 csv files from 3 folders

How do I rbind all the files from different folders? and it should be done in D: drive
Please help

Thank you

First, you need to get all the file locations, if your folder names follow some pattern you can specify it with a "regular expression".

list_of_files <- list.files(path = "C:/",
                            recursive = TRUE,
                            pattern = "pattern/.*\\.csv$",  # You need to replace this by a regular expression suitable for your particular application
                            full.names = TRUE)

Then you can read all the files in the list at once with something like this

df <- readr::read_csv(list_of_files, id = "file_name")

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

1 Like

This topic was automatically closed 21 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.