Way to retrieve creator-type of OS X files?

Richard Gaskin ambassador at fourthworld.com
Thu Sep 16 13:47:04 EDT 2004


Robert Brenstein wrote:

>>>
>>> IMHO it would be reasonable to support platform-specific features 
>>> like these through an external.
>>
>>
>> Simple enough to script -- I wrote this one to get just the file type, 
>> but could easily be extended to include creator code:
>>
>>
>> function fwMacFileType pPath
>>   local tSaveDir, tShortFileName, tFileList, tLine, tType
>>   --
>>   put the directory into tSaveDir
>>   set the itemdel to "/"
>>   put the last item of pPath into tShortFileName
>>   delete last item of pPath
>>   set the directory to pPath
>>   put the detailed files into tFileList
>>   put lineoffset(cr&urlEncode(tShortFileName)&comma, cr&tFileList&comma)
>>  into tLine
>>   if tLine > 0 then
>>     set the itemdel to comma
>>     put last item of line tLine of tFileList into tType
>>   end if
>>   set the directory to tSaveDir
>>   return tType
>> end fwMacFileType 
> 
> But it can't be extended to get the finder label, for example.

True.  I was merely offering an immediate solution for the original 
poster's request.  The label property would be a good nice-to-have -- 
obtainable via AppleScript?

> I am also curious about performance when calling this function 50 times 
> for a folder with 800 image files.

Why 50 times if the folder contains 800 files?

I wouldn't use that function for multiple files, as it's designed for 
single files and it would be much faster to just grab "the detailed 
files" and parse the result for everything at once.

In fact, given the overhead of the XCMD interface and the latency 
inherent in file I/O, if you want to get the type and creator code for 
800 files in a folder I'd guess it would be faster to parse "the 
detailed files" than to call an external designed to work on single 
files that many times.

-- 
  Richard Gaskin
  Fourth World Media Corporation
  ___________________________________________________________
  Ambassador at FourthWorld.com       http://www.FourthWorld.com


More information about the use-livecode mailing list