Rename Files In Subfolders In R
I have a folder "Samples" with sub-folders named "A01" to "A11". Each folder contains 2 files i.e. probes.txt and snps.txt. I want to write a code that reads the subfolders names, go into each subfolder and rename the 2 text files with the subfolder name in it e.g. A01_probes.txt
I wrote this code and R and I can't work out what's the problem. For me, the length of both "from" and "to" are same!
Help!
for (i in 1:length(b))
{
setwd(b[i])
vr1<-cat(basename(b[i]),"pro.txt",sep="")
vr2<-cat(basename(b[i]),"s.txt",sep="")
file.rename("probes.txt",paste(vr1))
file.rename("snps.txt",paste(vr2))
}
Error in file.rename("probes.txt", paste(vr1)) : 'from' and 'to' are of different lengths
• 7,310 views
•
link
0 answers
No answers yet.
Log in to answer this question.
Try changing
catwithpaste. Please edit you code, it is hard to read.Thanks a bunch! it worked!
Can someone put the code in a code block so it renders properly?
As zx8754 alluded, cat doesn't return a value.
Sorry about that. I'm new here. Just fixed it.
Well, not a bionformatic question, and it's already solved, closing.
Sorry, the code was required to prepare input files for ASCAT (Allele specific copy number analysis in Tumors) algorithm for a particular array type. Will mention "bioinformatic" background next time if you "really" need it.
The forum requires any post to be bioinformatic-related, otherwise you will be directed to stackoverflow or similar sites. This is a rule #1 for Editors, not only me. Cheers.
Always when you used code like this you probably have a problems so I highly recomend Batch Rename Files Tool. You can easily found hier BatchRenameFiles.org