Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

How to rename dates to a different format?

Last post 11-21-2012, 4:58 PM by Aussie Susan. 1 replies.
Sort Posts: Previous Next
  •  11-21-2012, 5:38 AM 87112

    How to rename dates to a different format?

    Hi! 

     I want to use RegEx in Total Commander to rename files starting with dates to have different format. For example 2012-01-01 to be 2012.01.01 

     Dates are usually in the beginning of file names, but not always. Can it be possible to write a code to find the place with the date by itself and rename it accordingly? 

     How to do that? 

  •  11-21-2012, 4:58 PM 87113 in reply to 87112

    Re: How to rename dates to a different format?

    A quick search of the internet shows that the regex capabilities for Total Commander follow the basic regex syntax so the followion g may work. However I have no way to test these.

    The simplest way would be to substitute all "-" characters with ".". This would not need the regex capabilities, but would also change names such as

    2012-01-01 Hello-sailor.avi

    to

    2012.01.01 Hello.sailor.avi

    which may or may not be a problem.

    A regex pattern that would find dates of the structure you have shown would be

    (\d{4})-(\d\d)-(\d\d)

    and yo could then use a replacement string of

    $1.$2.$3

    However, you need to be careful that this will find every instance of this pattern of digits anywhere in the file name (and type presumably). If this is the case, then you will need to show us the full pattern of the way the files are named.

    By the way, I'm not sure if Total Commander will rename the whole file name or will allow a partial name substitution - I've assumed that it can as this is the way that the vast majority of regex engines work. Let me know if this is necessary.

    Susan

View as RSS news feed in XML