Regular Expression to rename a file name? RRS feed

  • Question

  • Hi All,

    I want to rename a file name using regular expression.

    Original File Name  : 000755SERV_Sort20MassMailingMultiPsd_20120828004643600_WIPrintDuplex_MassMailing_0001..00.gpg

    Renamed File name : 000755SERV_Sort20MassMailing20120828WIPrintDuplex0001.gpg

    Please help me to rename the original file name as renamed file name using regular expression.


    Varun Kumar

    Tuesday, August 28, 2012 5:54 PM


  • Hi Varun,

    Thank you for posting on this forum.

    If you want to just remove some part of a string and get just only one string, I think it is hard to achieve.

    In your case, the regular expression should be something like this:


    This will return you several groups, and you need one more operation to combine the matched groups to one string. And so far, there is no way to combine this groups in only one regular expression.

    So I suggest you just try substring method: by this way:

    string newName = oldName.SubString(a,b) + oldName.SubString(c,d) + ... 

    I hope this will be helpful.

    Best regards,

    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, August 29, 2012 11:32 AM