0

So this works:

  1. File1-suffix.txt
  2. ren "*-suffix.txt" "*-newsuffix.txt"
  3. File1-newsuffix.txt

But this fails:

  1. File1-suffixA-suffixB.txt
  2. ren "*-suffixA-suffixB.txt" "*-newsuffixA-suffixB.txt"
  3. File1-suffixA-newsuffixA-suffixB.txt

Why is the original suffixA retained?

I have studied the documenation here & here

However I see nothing regarding dashes causing problems.

GreyCloud
  • 1,326
  • 4
  • 13
  • 18

1 Answers1

2

The ren pattern substitution code does its job without any knowledge about what was originally matched by * in the "input" pattern – it only receives the replacement pattern and has to apply the wildcard rules anew. According to those rules, the function lets each * match as much as possible up to (not including) the last instance of the - character that follows; in your case, this means that the * in replacement pattern will match the entire File1-suffixA.

The source code indeed notes that it won't do the right thing in many cases. (See wildcard_rename() and WinEditName() in XPSP1/NT/base/cmd/cpwork.c on GitHub.)

grawity
  • 501,077