title: How to rename files with a specific pattern in R?
body: <p>There are some <a href="http://onlinelibrary.wiley.com/doi/10.1002/cyto.a.20825/abstract;jsessionid=249FEAB8AE92A9DC8229F4F8BB43104F.d03t02" rel="nofollow noreferrer">.fcs</a> files in a <em>data.000X</em> format (where X = 1, 2, 3...) in a directory. </p>
  
  <p>I want to rename every <em>n</em> file to the following format: <em>exp.fcs</em> (where <em>exp</em> is a text from a vector) if the file to be renamed is an <em>.fcs</em> file.  </p>
  
  <p><em>in other words</em>: I want to rename files to exp.txt, where <em>exp</em> is a text and not a consecutive letter(s) i.e. F, cA, K, etc.  </p>
  
  <p>For example, from:  </p>
  
  <pre><code>data.0001, data.0002, data.0003, data.0004, data.0005, data.0006...  
  </code></pre>
  
  <p>to  </p>
  
  <pre><code>textF_a.fcs, textF_b.fcs, textF_c.fcs, textVv_a.fcs, textVv_b.fcs, textVv_c.fcs ...  
  </code></pre>
  
  <p>I tried to do it with <a href="http://stat.ethz.ch/R-manual/R-patched/library/base/html/files.html" rel="nofollow noreferrer">file.rename(from, to)</a> but failed as the arguments have different lengths (and I don't know what it means):  </p>
  
  <pre><code>a &lt;- list.files(path = ".", pattern = "data.*$")  
  b &lt;- paste("data", 1:1180, ".fcs", sep = "")  
  file.rename(a, b)
  </code></pre>