How to use specific value extracted from the file in the name?

Advanced Renamer forum
#1 : 03/07-25 19:24
Chris
Posts: 2
I need to add to the filenames of many EML files the value of the Date: field within each file, e.g.

myfile.EML (containing Date: Mon, 30 Jul 2012 14:00:10 +0200)

to

myfile Mon, 30 Jul 2012 14_00_10 +0200.EML

Can Advanced Renamer do this?

Neither <File Content :pos:count:filename> nor <File Line:x> suffices given the position is variable. can see no way to get scripting to read the file content (but will ask separately about that).

Or (less likely I guess) any way specifically to add an EML's Date. Note that Windows property ItemDate is inaccuruate.

Thanks.

edited: 03/07-25 19:30
#2 : 03/07-25 23:29
Delta Foxtrot
Posts: 502
Reply to #1:

Hi Chris,

As a standard written in the early 1980s, rfc822 is something of a mess. The last update was around 2001, so good luck there... A decade before iPhone. And we seem to be stuck with the spaghetti-code of formats, since organizations need to be able to read emails sent from the 80s on.

That said, I found some .eml files on my system and every one had the date in the first line of the header. (They all are from the same email app though). If you are that lucky it won't be hard to extract the date using 1) a new name method comprised of "<Name>_<File line:1>"; then 2) various replace methods to strip unnecessary characters and format the date. It took me four methods, three replace and a list replace, to do it on my emails.

With a different header setup you'll need a script to get there. Do you have coding, especially javascript, experience? If not you'll probably need some help doing what you need.

I'd need to see sample email headers to see if I have the skills to get what you need. It might be as simple as reading header lines using "app.parseTags('File Line:'+n+'>')" in a loop to find the date, but I won't know without seeing what you are working with.

Or maybe Kim will have some other suggestion; as the creator of Advanced Renamer he's really the go-to guy for file format questions.

Using my .eml files, this script pulled the date and added it to the filename:

// -----------------------------------------------------
oldName = item.newBasename;
dateStack = app.parseTags( '<File Line:1>' ) ;
pattern = /(\d{4})(\d{2})(\d{2}) (\d{6})\.\d+ms (.*)/ ;
if ( pattern.test( dateStack ) ) {
newName = oldName + "_" + dateStack.replace( pattern, "$1-$2-$3 $4-$5" ) ;
}
pattern = /Date ([A-Za-z]{3}), (\d{1,2}) ([A-Za-z]{3}) (\d{4}) (\d{6}) .\d{4} \(([A-Z]+)\)/ ;
if ( pattern.test( dateStack ) ) {
newName = oldName + "_" + dateStack.replace( pattern, "$4-$3-$2 $5-$6" ) ;
}
return newName ;
// -----------------------------------------------------

(Minus converting Jan/Feb/Mar etc to numbers, which is nothing really).
EDIT: This is just a script version of the 4 methods I used to pull the date without a script. END EDIT

Adding a loop to query header lines *might* be all that's necessary to convert this to your format, but again, I won't know without seeing your header format(s).

Best,
DF

edited: 03/07-25 23:47