我对选择的名称扩展名有疑问 当我选择两个以上不同的文件类型时,它不起作用 请帮助
property doc_list : {"pdf", "doc"}
property image_list : {"jpg", "png", "tif", "tiff", "gif"}
tell application "Finder"
set sel to (get selection)
repeat with AnItem in sel
end repeat
if sel = {} then
display alert ("nothing selected")
else if name extension of AnItem is in doc_list then
display alert ("this is doc files")
else if name extension of AnItem is in image_list then
display alert ("this is images files")
else if name extension of AnItem is in image_list & doc_list then
display alert ("this is images and doc files")
else if name extension of AnItem is not in image_list & doc_list then
display alert ("unknown file type")
end if
end tell
答案 0 :(得分:0)
end repeat
行必须移至end tell
之前。
这是一个稍微改进的版本。第三个else if
子句将永远不会到达,而第四个子句只能是else
property doc_list : {"pdf", "doc"}
property image_list : {"jpg", "png", "tif", "tiff", "gif"}
tell application "Finder"
set sel to (get selection)
if sel = {} then
display alert ("nothing selected")
return
end if
repeat with AnItem in sel
set nameExtension to name extension of AnItem
if nameExtension is in doc_list then
display alert ("this is doc files")
else if nameExtension is in image_list then
display alert ("this is images files")
else
display alert ("unknown file type " & quote & nameExtension & quote)
end if
end repeat
end tell