how to add inside my filename numbers?

If you need help on how to use the program
Post Reply
theaether
Posts: 2
Joined: 2012-01-10 21:21:56

how to add inside my filename numbers?

Post by theaether »

I have documents in some kind of format such as:

ABCXYZ 20090410 (DRAFT) JR.doc
ABCXYZABC 20090501.pdf
ABCXYZDEFG 7-19-10.doc

I would like those to end up like:

ABCXYZ 2009-04-10 (DRAFT) JR.doc
ABCXYZABC 2009-05-01.pdf
ABCXYZDEFG 2010-07-19

The third one may be difficult, since the "10" has to be recognized as the year "2010" and swapped to the front of the line. But if that's too much, could you help me with the first two? Just putting in hyphens after the 4th and 6th numbers so that I get a YYYY-MM-DD format instead of YYYYMMDD?
antp
Site Admin
Posts: 9665
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Hi,
For the first two cases, you could use "regular expression" action
with the following expression:
^(.*)([0-9]{4})([0-9]{2})([0-9]{2})(.+)$
and the following as new name:
$1$2-$3-$4$5
(be sure to not leave a space at the end when pasting these lines)

For the 3rd case if the number of digits varies (1 or 2), it is probably possible, but much more complicated, and I am not good enough with regular expressions for that :D
theaether
Posts: 2
Joined: 2012-01-10 21:21:56

Post by theaether »

thank you for responding. would that code work if the number of strings that precede the 8 digit date that I want dashes to be inserted into varies? Sometimes the file name might be AAA BBB CCC 20101012 (3 strings before the date), or sometimes it might be 2 strings before.

thanks again
antp
Site Admin
Posts: 9665
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Yes, it will work, here is the explanation of the expression :

^ = beginning
(.*) = group of any characters (optional), including spaces
([0-9]{4}) = group of 4 digits
([0-9]{2}) = group of 2 digits
([0-9]{2}) = group of 2 digits
(.+) = group of any characters (at least one), including spaces
$ = end

So as long as there is a group of 8 digits somewhere, what is in front or after does not matter.
The $+number used in the new names are reference to each of the groups listed above
Serbul
Posts: 1
Joined: 2012-01-24 08:43:47

add this dialog to help file

Post by Serbul »

Antoine, this dialog is a great clear example of how to use Regular expressions. You really should put it in the AntRenamer help file.
Current info about Regular expressions in help file and by a web link ibid is too detailed and complex to understand at a glance.
antp
Site Admin
Posts: 9665
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Indeed, it would be a good improvement to the help file to have a very basic explanation like that.
Many things could be done with the basic operations used here.
noclick
Posts: 1
Joined: 2012-02-15 06:55:43

Post by noclick »

for the third one
using regular expression:

Expression:
^(.*)([0-9]{1,2})-([0-9]{1,2})-([0-9]{2,4})(.+)$
New name:
$1 $4-$2-$3$5

Result:
ABCXYZDEFG 7-19-10.doc
BE RENAMED TO :
ABCXYZDEFG 10-07-19.doc

but the main problem is how to rename "10" to "2010",and if add "20" in the frot directly , problem will come when year is "2010", confused too

waiting for the answer..
antp
Site Admin
Posts: 9665
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

You could run a separate expression to replace space + 2 numbers by 20 + number, but I do not know how to integrate that in the other expression (maybe possible).
Post Reply