• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Is it a file or folder?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is it a file or folder?


  • Subject: Re: Is it a file or folder?
  • From: "Marc K. Myers" <email@hidden>
  • Date: Mon, 29 Jan 2001 17:42:45 -0500
  • Organization: [very little]

harry brindley wrote:
> Date: Mon, 29 Jan 2001 15:36:48 -0500
> To: email@hidden
> From: harry brindley <email@hidden>
> Subject: Is it a file or folder?
>
> 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

What you want to do can't be done. There is no way to tell what an item
is from a list of names. Snip1 works because the list produced by a
drag-n-drop operation is a list of aliases which the Finder can use to
get to the actual stored item and determine what it is. Snip2 doesn't
work because all you've got is a list of names. It's like saying, "How
old is George?" In that context, a name is not sufficient to find an
individual. OTOH, if you've got a variable set to the containing folder
you could say:

set fileType to file type of item theItem of folder theFolder

That way you could avoid full paths and aliases for each item. I like
aliases. What a great invention!

Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074

[1/29/01 5:41:26 PM]


  • Prev by Date: Help with Sequentia/Wait script execution
  • Next by Date: Re: Reading Files bit by bit... help please.
  • Previous by thread: Re: Is it a file or folder?
  • Next by thread: Re: Is it a file or folder?
  • Index(es):
    • Date
    • Thread