title: Read files from Multiple subfolders as a list
body: <p>I have a Main directory with several sub folders consisting of raster files. I would like to read all the files in the sub folders but I don't want them all together. Instead I want them in a list where the first element of the list would be all the files from the first subfolder, second element- all files from the second subfolder and so on. I already found one <a href="https://stackoverflow.com/questions/56633551/how-can-i-import-multiple-fasta-files-from-multiple-subfolders-into-a-list-of-li">question</a> which was similar to my problem but there wasnt any answer. I know you could use list.files with recursive to read all files within a subfolder like</p>
  <pre><code>dat.files  &lt;- list.files(path=&quot;C:/Main dir&quot;,
                           recursive=T,
                           pattern=&quot;*.tif$&quot;
                           ,full.names=T)
  </code></pre>
  <p>but this brings a single character vector of all files instead of lists of character vectors depending on the subfolder position like [ chr vector 1st folder, chr vector 2nd folder,.....so on]</p>
  <p>Is there a way to do this or has this already been answered? Any suggestions or helps are welcomed and appreciated.</p>
  <p><strong>EDITED</strong>
  Based on @stefan s suggestion, I did it by two steps which worked. I will add how I did it</p>
  <pre><code>dir.files  &lt;- list.dirs(path=&quot;Main dir&quot;, recursive = F) 
  dat.files &lt;- lapply(dir.files, list.files)
  </code></pre>