Getting the type code of a file under OSX

Ken Ray kray at sonsothunder.com
Sat Jul 30 19:08:58 EDT 2005


On 7/30/05 4:48 PM, "Joel Guillod" <joel.guillod at net2000.ch> wrote:

> Hi Eric,
> 
> 
>> So, I propose another approach:
>> As usual, is this one the last one?
>> :-)
>> [...]
>> function CreatorAndType pFilePath

Man, I was out all day and say this thread... just to add *one more*
approach, here's what I do, and it returns all of the attributes of a file
or folder into an array so I can just get the array element I need:


on mouseUp
  answer file "Get a file:"
  if it <> "" then
    put stsFileInfo(it,"file") into tDocInfoA
    put tDocInfoA["creatorType"]
  end if
end mouseUp

If I selected a Word document, this would return "MSWDW8BN".

----------------------------------------------------------------------
--| FUNCTION: stsFileInfo
--|
--| Author:   Ken Ray
--| Version:  1.0
--| Created:  3/4/04
--| Last Mod: --
--| Requires: --
--|
--| Retrieves the file/folder information on a specific file/folder in a
parseable array
----------------------------------------------------------------------

function stsFileInfo pFilePath,pType
  -- supports keys of
"full,fileName,dataSize,resSize,createDate,modDate,accessDate,BUdate,ownerID
,groupID,permissions,creatorType,Size"
  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
  if pType = "file" then
    put the detailed files into tDetailedList
  else
    put the detailed folders into tDetailedList
  end if
  set the directory to tOldDir
  set the itemDel to ","
  put lineOffset(cr&tItem&",",cr&tDetailedList) into tLine
  put line tLine of tDetailedList into 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"]
  return tFileA
end stsFileInfo

HTH,

Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com





More information about the use-livecode mailing list