File Properties

Kay C Lan lan.kc.macmail at
Wed Jan 2 22:01:25 EST 2013

On Wed, Jan 2, 2013 at 2:16 AM, Todd Geist <todd at> wrote:
> I found Trevor's FilesAndFolders library, and he has a fileGetInfo function
> in there.  Thanks Trevor, but wow, thats a lot of work to get the file
> Properties.

Couldn't find Trevor's FilesAndFolders so not sure how complex it is,
but in line with an earlier post of mine about the niceties of using
LC with Unix tools, here's a possible solution that will work on Linux
and Mac, and I believe Win (but not certain).

Check the man page for ls - type 'man ls' (without single quotes) at
the prompt in a Terminal window or use Bwana on Mac:

You'll note the -l option gives the long output which includes the
modification date and time; something like this:

-rw-r--r--@ 1 yourname  staff  434086  4 Dec 00:31
/Users/yourname/Documents/Dropbox/MX Bus Timetables/S8.pdf

Although ls normally outputs all the files from a directory, as stated
in the synopsis you can just use a single file name if that's all
you're after. So in LC you could

--previous script that extracts full path name into tPathName
--surround tPathName in single quotes
--this avoids problems if folder or file names include spaces
put "'" & tPathName & "'" into tPathName
--build shell command
put "ls -l" && tPathName into tShellCommand
--run shell command
put shell(tShellCommand) into tInfo
--extract just the date info
--this uses regex to extract the only instance of a single or double
digit, then space,
--followed by exactly 3 letters, then space, followed by exactly 2 digits,
--a colon another 2 digits, then a space
get matchText(tInfo,".+\s(\d{1,2} \w{3} \d{2}:\d{2})\s.+",tDateTime)
--or extract the date, month and time separately
--by using additional parenthesis ()
get matchText(tInfo,".+\s(\d{1,2}) (\w{3})
-- you now have the modification date and time
--do with it whatever you need to.

Richmond might point out that the regex in this case could be avoided by simply:

put word 6 of tInfo into tDate
put word 7 of tInfo into tMonth
put word 8 of tInfo into tTime

which would be correct, as in this case, users and group names cannot
be multi-word (contain spaces). But there are lots of output where the
data before the info you are looking for is many and varied, and the
data after the info your looking for is many and varied, but the info
itself is unique and follows a simple pattern, such as Date & Time,
email address, web address, specific file names; etc, etc. In these
cases matchText and regex is your friend.

As I stated in an earlier post, with regex I always test it first in
RegExhibit - OS X
because if it works in RegExhibit it works with LC's matchText(). So
if I'm using shell() I always test it first by running the command in
Terminal  - OS X. If you are on Mac you should know the easiest way to
get a full file pathname into Terminal is simply drag and drop; so
type 'ls -l ' (with a trailing space but no quotes) at the prompt and
then drag a file into the Terminal Window - then press Return. The
only other thing to NOTE is if you do this, instead of surrounding
pathnames with single quotes Terminal will automatically escape spaces
in folder and file names with the back slash character: Multi Word
File Name becomes Multi\ Word\ File\ Name.


More information about the Use-livecode mailing list