Why if you use rename.file in R it did not rename existing file but created another one?
<p>I wanted to rename the existing files in my working directory following this <a href="https://stackoverflow.com/questions/10758965/how-do-i-rename-files-using-r">link</a>
using the part of the existing name. This is the list of file names</p>

<pre><code>&gt; files_names
 [1] "./AKLBNE_oneway_JobId427508.csv" "./AKLMEL_oneway_JobId427512.csv"
 [3] "./AKLSYD.csv"                    "./AMSPEK_oneway_JobId427522.csv"
 [5] "./ATXDXB_oneway_JobId427524.csv" "./AUHLHR_oneway_JobId427528.csv"
 [7] "./BAHDXB_JobId427533.csv"        "./BHMDXB_oneway_JobId427557.csv"
 [9] "./BKKDOH_oneway_JobId427563.csv" "./BKKFRA_JobId427565.csv"       
[11] "./BKKHKG_JobId427568.csv"        "./BKKKIX_JobId427572.csv"       
[13] "./BKKNRT_JobId427575.csv"        "./BNEAKL_oneway_JobId427577.csv"
[15] "./BOMDXB_JobId427581.csv"        "./BRUDXB_JobId427583.csv"       
[17] "./CANLAX_JobId427585.csv"        "./CANPVG_JobId427588.csv"       
[19] "./CDGCUN_JobId427590.csv"        "./CDGDXB_JobId427594.csv"       
[21] "./CDGIAD_JobId427596.csv"        "./CDGJFK_JobId427598.csv"       
[23] "./CDGKUL_JobId427600.csv"        "./CDGLHR_JobId427603.csv"       
[25] "./CDGNRT_JobId427605.csv"        "./CDGSFO_JobId427607.csv"       
[27] "./CDGYUL_JobId427610.csv"        "./CTUPEK_JobId427613.csv"       
[29] "./SINCDG.csv"
</code></pre>

<p>This is the code I wrote:</p>

<pre><code>destination&lt;-vector(length = length(files_names))
for (i in 1:length(files_names)){
  files_names&lt;-list.files(pattern = "*.csv", full.names = TRUE)
  destination[i]&lt;-substr(files_names[i],3, 8)
  file.rename(files_names[i], paste(destination[i]))
}
</code></pre>

<p>But instead of renaming it created another files in my working directory. What is the problem?  </p>