Is it a file or folder?
Is it a file or folder?
- Subject: Is it a file or folder?
- From: harry brindley <email@hidden>
- Date: Mon, 29 Jan 2001 15:36:48 -0500
I want to be able to tell a file from a folder from list of the
contents of a given folder. In this situation I do not have the full
path name to work with and cannot check for a trailing colon to know
whether I have a folder or not.
I can get it to work through snip.1, in a drop environment. I cannot
get it to work in snip.2 where I "set theList to list folder
sourcePath" since it appears that the contents of my list is no
longer recognised as file names -- probably a coercion issue.
Is my strategy to use the file type of "fold" to recognise a folder a
good one (assuming that if not "fold" then it must be a file) and, if
so, how do I set about fixing snip.2 ?
Please reconnect broken lines at the dots ...
-- snip.1
-- drops files and folder on me
-- to find out which are files and which are folders
on open (theList)
tell application "Finder"
repeat with theItem in theList
set fileName to name of theItem
set fileType to file type of theItem
if fileType is "fold" then
set fileFolder to "folder"
else
set fileFolder to "file"
end if
display dialog "Item " & fileName & " is a " & fileFolder ...
... buttons {"Cancel", "OK"} default button 2
end repeat
end tell
end open
-- snip.2
-- specify a folder of items
-- to find out which are files and which are folders
set sourcePath to "hard Disk:Desktop Folder:trashMe"
set theList to list folder sourcePath
tell application "Finder"
repeat with theItem in theList
set fileName to name of theItem
set fileType to file type of theItem
if fileType is "fold" then
set fileFolder to "folder"
else
set fileFolder to "file"
end if
display dialog "Item " & fileName & " is a " & fileFolder ...
... buttons {"Cancel", "OK"} default button 2
end repeat
end tell
Thanks, in advance, for the help!
Harry