title: R: locating files that their names contain a specific string from a directory and match to my list of wanted files
body: <p>It's me the newbie again with another messy file and folder situation(thanks to us biologiests): I got this directory containing a huge amount of .txt files (~900,000+), all the files have been previously handed with inconsistent naming format :(</p>
  
  <p>For example, messy files in directory look like these:</p>
  
  <pre><code>ctrl_S978765_uns_dummy_00_none.txt
  ctrl_S978765_3S_Cookie_00_none.txt
  S59607_3S_goody_3M_V10.txt
  ctrlnuc30-100_S3245678_DMSO_00_none.txt
  ctrlRAP_S0846567_3S_Dex_none.txt
  S6498432_2S_Fulra_30mM_V100.txt
  .....
  </code></pre>
  
  <p>As you see the naming has no reliable consistency. What's important for me is the ID code embedded in them, such as S978765. Now I have got a list (100 ID codes) of these ID codes that I want. </p>
  
  <p>The CSV file containing the list as below, mind you the list does have repetitive ID codes in the row due to different CLnumber value in the second columns:</p>
  
  <pre><code>ID code  CLnumber
  S978765  1
  S978765  2
  S306223  1
  S897458  1
  S514486  2
  ....
  </code></pre>
  
  <p>So I want to achieve below task: find all the messy named files using the code IDs by matching to my list. And copy them into a new directory. </p>
  
  <p>I have thought of use list.files() to get all the .txt files and their names, then I got stuck at the next step at matching the code ID names, I know how to do it with one string, say "S978765", but if I do it one by one, this is almost just like manual digging the folder. </p>
  
  <p>How could I feed the ID code names in column1 as a list and compare/match them with the messy file title names in the directory and then copy them into a new folder?</p>
  
  <p>Many thanks,
  ML</p>