How to add path to the list od list.files

Hello,

I have listed the files from a directory. How can I attach the path to the file names?

 old_files <- list.files(paste("~/Development/glycoPipeApp/OUT/openMS/INPUT_DATA/INPU_DATA_OUT/", old_file[i], sep = ""), pattern = "[0-9].csv"))

#Now I need to add the path to the files.  I started by using a loop
  for(i in 1:length(old_files)){
     old_path[i] <- paste("~/Development/glycoPipeApp/OUT/openMS/INPUT_DATA/INPU_DATA_OUT/", old_files[i], sep = "")
  }

#but it does not work. Ir produces and extra path, with an NA attached to it in place of the file name.

This doesn't directly answer your question, but just wanted to point out that list.files() includes a full.names argument that might be helpful for you.

full.names a logical value. If TRUE , the directory path is prepended to the file names to give a relative file path. If FALSE , the file names (rather than paths) are returned.

1 Like

Yes, that answers my question. thank you!