Rename Files: paste-prefix

Suppose in ./docs I have some PDF files e.g. 1-Intro.pdf, 2-Topics.pdf etc. How do I paste 1- as prefix ? For example, 1-Intro.pdf will become 1-1-Intro.pdf.

This is better done with a shell script outside R

for f in *.pdf; do mv -- "$f" "1-$f.pdf"; done

Something like this should work (not tested):

pdf_files <- list.files(pattern = "*.pdf") # adapt as required
file.rename(pdf_files, paste0("1-", pdf_files))
1 Like

Thanks! It works perfectly.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.