SC, Image Files and MPI

Folder Drag and Drop (2)

You might notice that the script listing image files from a folder drop is very slow. I think this is due to calling an appleScript for each file we are testing for type.
When we tested from files dropped we got the file type from the drop:
put item 1 of dragData(x, "hfs ",type ) into tFileType

and then used this function to test file type:
function AltIsGraphicFile pfileType,pFilePath
if COMMA&pfileType&COMMA is in ",GIFf,JPEG,8BPS,JPEG,BMPf,jp2 ,PDF ,PICT,PNTG,qtif,.SGI,TPIC,TIFF,pct,"  then return true

set the itemDel to "."
if COMMA&last item of pfilePath&COMMA is in ",psd,gif,jpg,jpeg,bmp,jp2,pdf,pict,pntg,qtif,sgi,tga,tiff," then return true
return false
end AltIsGraphicFile


If we use Dir a bit more efficiently we can get file types from it too. We were using
put Dir (pFilePath,false,true) into tfileList
which returns a list of files but we can use
put dir (pFilePath,false,true,Cr&comma) into tfileList
Which returns a list with lines like this:
HD X:Users:johnjohn:Sites:chiron:gallery:htmlg2:the images:10k.jpg,3164786067,3164786067,0,F,0,0,F,JPEG,prvw,22814,24576,0,0
we are interested in the 1st item (file path) and 9th item (file type) in each line. So our listFolderImages function should look like this:
 function listFolderImages pFilePath  

if last char of pFilePath is not colon then put colon after pFilePath
put Dir (pFilePath,false,true,Cr&comma) into tfileList
repeat with x = the number of lines in tfilelist down to 1
if not AltIsGraphicFile(item 9 of line x of tFileList,item 1 of line x of tfileList) then delete line x of tfilelist
else put item 1 of line x of tfilelist into line x of tFileList
end repeat
return tfilelist
end listFolderImages


The only images that will not get listed are ones with no traditional mac file type and no file extension.