I have a directory which has 5 files named like this
A.abcd (1).txt
B.abcd (1).txt
C.abcd (1).txt
D.abcd (1).txt
E.abcd (1).txt
I want to change the names of the file so that they should become like this :
A.defg.txt
B.defg.txt
C.defg.txt
D.defg.txt
E.defg.txt
In short I want to change abcd (1) to defg in the files.
I tried to run the system command from the R console.
system("mv A.abcd (1).txt A.defg.txt")
But I have to do this one by one.
Is there any way I can do it in one shot through R ??
You can use
file.rename()to rename files. And usesubwith a regular expression for the text manipulation.See
?filesfor help on this and the other base R file manipulation functions.