Is a file an image?
Alex Adams
alex at a2technology.com
Tue Jan 26 15:44:24 EST 2010
If you're going to be making the judgment based on the extension, why don't
you just put the possibilities in a switch/case statement and take care of
it locally?
--
Alex Adams
hawkVision tools for solving Wicked Problems
(a)2 Technology Partners, Inc.
831-726-8013
alex at a2tecnology.com
www.a2technology.com
www.promisstudio.com
universalconnector.wordpress.com
> From: David Bovill <david at architex.tv>
> Reply-To: How to use Revolution <use-revolution at lists.runrev.com>
> Date: Tue, 26 Jan 2010 20:19:00 +0000
> To: How to use Revolution <use-revolution at lists.runrev.com>
> Subject: Is a file an image?
>
> I've just dug out this very old and pretty untested script for detecting
> whether a file is an image. Seems to sort of work on OSX - included here for
> insiration :) Does anyone know a better way to do this?
>
> function file_GetType filePath
>> switch the platform
>> case "MacOS"
>> put spotlight_Kind (filePath) into fType
>> return word -1 of fType
>> case "Win32"
>> put offset(".",filePath) into tChar
>> if tChar <> 0 then
>> put char tChar to length(filePath) of filePath into text
>> put
>> queryregistry("HKEY_CLASSES_ROOT\"&(queryregistry("HKEY_CLASSES_ROOT\"&tExt&
>> "\")) & "\") into tType
>> else
>> put "" into tType
>> put "" into text
>> end if
>> if tType = "" then
>> if text <> "" then
>> delete char 1 of text -- remove "."
>> put toupper(tExt) && "File" into tType
>> else
>> put "File" into tType
>> end if
>> end if
>> return filePath & numtochar(9) & tType
>> default
>> return empty
>> end switch
>> end file_GetType
>>
>
> function spotlight_Kind someFile
>> put spotlight_GetAttribute(someFile, "kMDItemKind") into someKind
>> put word 1 to - 1 of someKind into someKind
>> delete char 1 of someKind
>> delete char -1 of someKind
>> return someKind
>> end spotlight_Kind
>>
>> function spotlight_GetAttribute someFile, attributeName
>> put spotlight_FileInfo(someFile) into spotlightFileInfo
>> return spotlight_ExtractAttribute(spotlightFileInfo, attributeName)
>> end spotlight_GetAttribute
>>
>> function spotlight_FileInfo someFile
>> put "mdls" into someShell
>> if someFile is not empty then
>> -- shell_BashParamEscape someFile
>> put space & someFile after someShell
>> end if
>> get shell(someShell)
>> return line 2 to -1 of it
>> end spotlight_FileInfo
>>
>> function spotlight_ExtractAttribute spotlightFileInfo, attributeName
>> if char 1 to 7 of attributeName is not "kMDItem" then put "kMDItem"
>> before attributeName
>> put "(?im)" & attributeName & " += +(.*)" into someReg
>> if matchtext(spotlightFileInfo, someReg, someValue) is true then
>> return someValue
>> else
>> return empty
>> end if
>> end spotlight_ExtractAttribute
>>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
More information about the use-livecode
mailing list