Announcement

Collapse
No announcement yet.

Rename File by inserting a numeric string using Regular Expression

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Rename File by inserting a numeric string using Regular Expression

    Select the following files to rename by inserting the letter "w".
    A.txt
    B.txt
    Old Mask: (.*).txt New Mask: $1w.txt
    The renamed files now contain the letter "w"
    Aw.txt
    Bw.txt

    However, if instead of inserting the letter w, we want to insert a number (2015), the rename does not work.
    New Mask: $12015.txt
    We want the renamed files to be A2015.txt and B2015.txt. However, A.txt is renamed to $12015.txt and the other file is skipped.

    Regular Expressions probably does not know if we are dealing with variable $1 or $12 or $120, etc. I searched online, but could not find a solution.

    Does anyone have the answer?

  • #2
    Hello,

    The mask you would be looking for is:
    (.*)\.txt
    and a New mask of
    $1\2015.txt

    The \ is usually the escape character for Regular Expressions. I also added it in the Old mask, as \. = ".", while just . is a mask character for any single character that just happens to match on . in this case.
    Aaron P Scooter Software

    Comment


    • #3
      I do not know regular expressions, but I have a couple of ideas.
      If You choose "DOS compatible" and not "Regular expressions", You can use "?2015.txt".
      If the files have different names, such as "AAA.txt" and "BBB.txt", You can use "???2015.txt".
      Instead, with regular expressions, what happens if instead of "$12015.txt" You use "$1_2015.txt"?
      Does it work for You?
      I mean, I tested it and in my case it works, but You have to check if it is OK for You to have the "_" or another character to separate "2015" from the variable "$1".


      Regards

      Rodolfo Giovanninetti

      Comment

      Working...
      X