Getting the type code of a file under OSX

Eric Chatonet eric.chatonet at sosmartsoftware.com
Sat Jul 30 05:12:50 EDT 2005


Hi Howard,

You could use AppleScript but doing this with Transcript is easy and  
fast:

function CreatorAndType pFilePath
   local tDefaultFolder,tCreatorType
   -----
   if the platform <> "MacOs" then return "Error: filetype not  
supported"
   put the defaultFolder into tDefaultFolder
   set the itemdel to slash
   set the defaultFolder to item 1 to -2 of pFilePath
   put urlDecode(the detailed files) into tFiles
   put line lineOffset(item - 1 of pFilePath,tFiles) of tFiles into  
tFile
   set the defaultFolder to tDefaultFolder
   set the itemDel to comma
   put item 11 of tFile into tCreatorType
   if tCreatorType = empty then return "Error: could not find the  
filetype"
   return char 1 to 4 of item 11 of tFile & comma & char 5 to 8 of  
item -1 of tFile
   -- creator and type separated by a comma
end CreatorAndType

Best Regards from Paris,

Eric Chatonet.

Le 30 juil. 05 à 01:56, Howard Bornstein a écrit :

> I wanted to check to see if I'm missing something obvious. I want to
> be able to get the type code of a specific file under OSX. As far as
> I've been able to find, there is only one way to get the type code--
> with the files function. The detailed files includes the type and
> creator codes. However, this gets the entire list of files in the
> default folder. Unless there's something I'm missing, the sequence
> would be something like this:
>
> 1) Get the full path of the file you want the type code for
> 2) Extract the folder it's in
> 3) Set the default folder to that folder
> 4) Get the detailed files
> 5) Compare the file name with item one of every line in the files
> 6) When you find a match, extract the last item from the detailed file
> description which is the type/creator code.
>
> This seems like a lot of work, just to get an attribute of a file. We
> have the filetype property, where we can set the type of a file. Isn't
> there a simple way to *get* the type of a file?

----------------------------------------------------------------
So Smart Software

For institutions, companies and associations
Built-to-order applications: management, multimedia, internet, etc.
Windows, Mac OS and Linux... With the French touch

Free plugins and tutorials on my website
----------------------------------------------------------------
Web site        http://www.sosmartsoftware.com/
Email        eric.chatonet at sosmartsoftware.com/
Phone        33 (0)1 43 31 77 62
Mobile        33 (0)6 20 74 50 86
----------------------------------------------------------------




More information about the use-livecode mailing list