Entering edit mode
10.6 years ago
Jason
▴
20
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