Getting the Last Modified Date of a file

Richard Gaskin ambassador at fourthworld.com
Sat Jun 30 17:33:13 EDT 2012


Peter Haworth wrote:
> I see you can get the last modified date of all the files in the default
> folder using the detailed files construct.  Is there not a way to get the
> same info for a specific file in any folder without having to mess around
> changing the default folder and filtering out the list for the one you want?

True, no out-of-the-box one-liner, but you can write a function to make 
it a one-liner easily enough - here's one from stdlib, in the Files 
section of the Rev Interoperability Project:


----------------------------------------------------------------------
--| FUNCTION: stdFileInfo
--|
--| Author:   Ken Ray
--| Version:  1.1
--| Created:  3/4/04
--| Requires: --
--|
--| Retrieves the file/folder information on a specific file/folder,
--| either as a raw value or in a parseable array.
--|
--| If <pOpt_InfoItem> is empty, you will get back the line from the
--| 'detailed files' in its entirety.
--|
--| If <pOpt_InfoItem> is one of "fileName","dataSize","resSize",
--| "size" (a combination of "dataSize" and "resSize"),
--| "createDate","modDate","accessDate","BUdate","ownerID", "groupID",
--| "permissions","creator", "type", or "creatorType" (a combination of
--| "creator" and "type"), only that value is returned.
--|    put stdFileInfo("/Users/ken/test.txt","creatorType")
--|    --> TTXTtext
--|
--| If <pOpt_InfoItem> is "array", you get back all the items in an
--| array that you can then use one of the info "keys" above to get at
--| the value you're interested in, with "full" giving you the full
--| detailed files line.
--|    put stdFileInfo("/Users/ken/test.txt","array") into tFileA
--|    put tFileA["creatorType"]
--|    --> TTXTtext
----------------------------------------------------------------------

function stdFileInfo pFilePath,pOpt_InfoItem
   if pOpt_InfoItem <> "" then
     if pOpt_InfoItem is not among the items of 
"full,fileName,dataSize,resSize,createDate,modDate,accessDate,BUdate,ownerID,groupID,permissions,creatorType,size,creator,type,array" 
then
       return "StdLibError: '" & pOpt_InfoItem & "' is not a valid file 
property."
     end if
   end if
   set the itemDel to "/"
   put urlEncode(last item of pFilePath) into tItem
   delete last item of pFilePath
   put the directory into tOldDir
   set the directory to pFilePath
   put the detailed files into tDetailedList
   set the directory to tOldDir
   set the itemDel to ","
   put lineOffset(cr&tItem&",",cr&tDetailedList) into tLine
   put line tLine of tDetailedList into tDetailedInfo
   if pOpt_InfoItem = "" then return tDetailedInfo
   replace "," with tab in tDetailedInfo
   set the itemDel to tab
   put tDetailedInfo into tFileA["full"]
   put urlDecode(item 1 of tDetailedInfo) into tFileA["fileName"]
   put (item 2 of tDetailedInfo) into tFileA["dataSize"]
   put (item 3 of tDetailedInfo) into tFileA["resSize"]
   put (item 2 of tDetailedInfo) + (item 3 of tDetailedInfo) into 
tFileA["size"]
   put "createDate,modDate,accessDate,BUdate" into tDates
   replace "," with tab in tDates
   repeat with x = 4 to 7
     put item x of tDetailedInfo into tSecs
     if tSecs <> "" then convert tSecs to short date and time
     put tSecs into tFileA[(item x-3 of tDates)]
   end repeat
   put (item 8 of tDetailedInfo) into tFileA["ownerID"]
   put (item 9 of tDetailedInfo) into tFileA["groupID"]
   put (item 10 of tDetailedInfo) into tFileA["permissions"]
   put (item 11 of tDetailedInfo) into tFileA["creatorType"]
   put (char 1 to 4 of item 11 of tDetailedInfo) into tFileA["creator"]
   put (char 5 to 8 of item 11 of tDetailedInfo) into tFileA["type"]

   if pOpt_InfoItem = "array" then
     return tFileA
   else
     return tFileA[pOpt_InfoItem]
   end if
end stdFileInfo



--
  Richard Gaskin
  Fourth World
  LiveCode training and consulting: http://www.fourthworld.com
  Webzine for LiveCode developers: http://www.LiveCodeJournal.com
  Follow me on Twitter:  http://twitter.com/FourthWorldSys




More information about the use-livecode mailing list