File date and size

Hi all

In VBA Office we normal use




to get the date/time and size of a file.

But because of the problem with long file names on a Mac this will not work
on long file names so I want to create a VBA function that call a Applescript that can do it.

Can anybody give me a example to get the size and date and time of a file

Thank you very much

set fpath to "BoxxyDisc:Jazz Flac Collection 4:iTunes:iTunes Media:Music:Anna Domino:Anna Domino:01 Rythm.m4a"

set f to alias fpath

tell application "System Events"
	set FileDateTime to creation date of f
	set FileLen to size of f
end tell

set the clipboard to (FileDateTime & tab & FileLen) as text
-- 2 de Dezembro de 2012 13:28:36	26500678

Thanks mouramartins

With this info I can make the VBA function, thanks for your reply.
If there are other ways I love to hear them.

Have a nice day

This is better, unless you know for sure that the current value of AppleScript’s text item delimiters is {“”} or “”:

set the clipboard to (FileDateTime as text) & tab & FileLen

I see: a date is not text or record then the & assumes it’s a list. :o

Yeah. Basically, AppleScript concatenations go like this:

-- Pseudocode. Don't try to compile!

If the item (or result) to the left of '&' is a list, a record, or a text then
	if the item to the right is of the same class as the item to the left then
		concatenate the two items
	else if the item to the right can be coerced to the same class as the item to the left then
		implicitly coerce the item to the right to that class
		concatenate the item to the left and the result
	end if
	create a list containing the two items, in the same left-right order
end if

--> The result of a concatenation is always a new object, not an extended original.

For completeness, although straying somewhat from the thread topic, here are a few consequences which people don’t often have to consider:

{1, 2} & "Hello"
--> {1, 2, "Hello"} ("Hello" was coerced to list before the actual concatenation.)
{1, 2} & {"Hello"}
--> {1, 2, "Hello"} (Same result. {"Hello"} was already a list.)
{1, 2} & {{"Hello"}}
--> {1, 2, {"Hello"}}

{1, 2} & {a:3}
--> {1, 2, 3} (The record was coerced to list before the actual concatenation.)
{1, 2} & {{a:3}}
--> {1, 2, {a:3}}
{} & {a:3}
--> {a:3} ({} can be either an empty list or an empty record for concatenation purposes.)

And of course the effect when concatenating records:

{a:1, b:2, c:3} & {a:10, c:30, y:40, z:50}
--> {a:1, b:2, c:3, y:40, z:50} (Properties from both records, values of common properties from the left record.)

How interesting. :slight_smile:

Here are some more results, mostly regarding what happens when text is concatenated with numbers and lists.

set a to "text "
set b to 0
set c to a & b
--> "text 0"

set d to b & a
--> { 0, "text " }
set f to {0}
set g to a & f
--> "text 0"

set h to {0, 8}
set i to a & h
--> "text 08"
set j to h & a
--> {0,8,"text "}

[offtopic mode=on]In reply to McUser’s footnote: Now I believe that they say that the Benelux is per user/square KM the biggest oil consumer in the world. Shame on me :P[offtopic mode=off]

I don’t get it, and you are forgiven for figuring out the xxd hack to avoid using AS to write a file anyways today! :slight_smile:

Edit: I did get it! Looks nice huh?

Here are some more coercions to numbers this time. Just to reaffirm.

set a to 8
set b to {9}
set c to a + b
return c
--> 17
set d to b + a
--> 17
set e to {8}
set f to e + b
--> 17 
set g to "8"
set h to g + b
--> 17 

[ offtopic mode continues to be on ]

[ offtopic off]

Hi Scripters

Is it possible to get a numeric value of the date and time instead of a text string

VBA FileDateTime will give you for example


And you can format as you want

You can try searcing here. :slight_smile:

Search for date and Nigel Garvey.

And by the way, the Date systems of MSOffice and Applescript isn’t the same. At least it is so with Office 2008 for Mac.

Bash’s date can do fun stuff

do shell script "date -jf '%Y%m%d%H%M%S' 20110708121212 +%s"

I go check this out this evening


I create a VBA function of the apple script but it is to slow when you must call it each time when you want to list all files you want on a worksheet and add the add and size for example.

Think more about it this evening/weekend

If you are using dates from an Excel worksheet, I urge you to check out if two dates, one from AppleScript, and one from Excel has the same daynumber.

A work around is to convert both dates to Unix Epoch time, if the daynumbers differ.