-3

I have a batch of PDF files in a folder and I am trying to rename them.

Example:

File1_20170501_data.pdf
File2_20170401_statistics.pdf
Sale2_20170404_Misc.pdf

I only want to keep the first six characters of each file name (the five characters left to underscore and the underscore) and replace everything behind with sample data.

The final file names should be:

File1_sample data.pdf
File2_sample data.pdf
Sale2_sample data.pdf

Anyone can advice which command line to use for this file renaming task?

Mofi
  • 46,139
  • 17
  • 80
  • 143
Ka Li
  • 31
  • 1
  • 3
  • 2
    What have you tried so far, [edit](https://stackoverflow.com/posts/50177422/edit) your question to show us your code even if not working. –  May 04 '18 at 15:48
  • 1
    What if there arise collisions? for example, if there are two files `File1_foo.pdf` and `File1_bar.pdf`? – aschipfl May 04 '18 at 17:12

1 Answers1

2

Given your provided information at the time of this answer, one simple command should do what you need:

Ren "C:\path to\a folder\?????_*.pdf" "?????_sample data.pdf"
Compo
  • 36,585
  • 5
  • 27
  • 39