I have a lot of images in a folder and I want to know the file type of it.
But I am not able to get it… Below are code
set myFolder to choose folder with prompt "Choose your folder containing Images"
tell application "Finder"
set tt to (count of every item in folder myFolder) as real
copy (list folder (myFolder) without invisibles) to fileList
-- set fileList to (list folder (myFolder) without invisibles)
--display dialog fileList
repeat with i from 1 to tt
set fn to item i of fileList
-- display dialog fn
set fn1 to file type of fn
display dialog fn1
--set fn1 to fn
-- display dialog fn1
-- set i to count of characters of fn1
-- set i to 1 - 2
-- tell application "Finder" to get file type
-- display dialog i
end repeat
set imageFile to (myFolder as text) & (item i of fileList as text)
set fileType to file type of imageFile
display dialog fileType
display dialog "HI"
end tell
set myFolder to choose folder with prompt "Choose your folder containing Images"
tell application "Finder"
set {filenames, filetypes} to {name, file type} of every document file of folder myFolder
end tell
repeat with i from 1 to count filenames
display dialog "File name: " & filenames's item i & return & "File type: " & filetypes's item i
end repeat
Of course, there’s no guarantee that your files will have file types assigned; depends on how they were obtained/created. You might want to go by name extensions instead.
set myFolder to choose folder with prompt "Choose your folder containing Images"
tell application "Finder"
set {filenames, filetypes, creatortypes} to {name, file type, creator type} of every document file of folder myFolder
end tell
repeat with i from 1 to count filenames
display dialog "File name: " & filenames's item i & return & "File type: " & filetypes's item i & return & "Creator type:" & creatortypes's item i
if (filetypes = "EPSF" or filetypes = "TIFF") then
display dialog "HI"
end if
end repeat
Remember that the variable filetypes is a list, Rajeev - so you need to specify which item in the list you want to compare:
if item i of filetypes is in {"EPSF", "TIFF"} then display dialog "HI"
However, if you’re trying to filter out only EPSF and TIFF files for processing, then you might consider doing it like this:
set myFolder to choose folder with prompt "Choose your folder containing images:"
tell application "Finder"
set imageList to myFolder's document files whose file type is in {"EPSF", "TIFF"}
(* do something with imageList *)
end tell