Skip to content
Prev 392698 / 398502 Next

rename files in R

Hi Rui,I put original file names and target file names into data frame: total_name. I can use
file.rename("out_1.pdf", "abc_title.pdf")

to rename a single file. But I hope to use loop to complete the task. So I write? a code below:
for (i in seq_len(nrow(total_name)))
{
? with(
? ? total_name[i, ],?
? ? {
? ? ? file.rename(total_name$orig, total_name$target)
? ? }
? )
}? ? ?
But I got error message:?
Error in file.rename(total_name$orig, total_name$target) :?
invalid 'from' argument

I think the problem happen due to quotation problem. Do you know how to fix it?
Thanks,
Kai On Friday, September 16, 2022 at 08:32:53 PM PDT, Rui Barradas <ruipbarradas at sapo.pt> wrote:
Hello,

My understanding of the problem is different, the files' first row is 
not tabular data, I might be wrong but it seems to me that it's 
something like

first row [of] file1.txt [is]:
abc.txt

file2.txt:
bed.txt

etc.

That's why the sapply loop reads one datum only and exits.

Hope this helps,

Rui Barradas

?s 02:29 de 17/09/2022, Ebert,Timothy Aaron escreveu: