Re: Two problems, MacOS X and Text Edit Plus
Re: Two problems, MacOS X and Text Edit Plus
- Subject: Re: Two problems, MacOS X and Text Edit Plus
- From: Christopher Nebel <email@hidden>
- Date: Mon, 15 Apr 2002 16:00:11 -0700
On Monday, April 15, 2002, at 12:39 AM, Peter Mathiessen wrote:
2.
Second, how do I script a foldercount?
I only want to count a folder to see if there is any files, if yes, the
script should continue. If not it should stop.
copy "Macintosh HD:Photo_and_illu_html_files:" as text to the_vol
set countfolder to (the_vol & "files_in:")
set foldercount to the count of every item of countfolder without
invisibles
if foldercount > 0 then
display dialog "Count: " & foldercount
end if
The result I get is "48", even if the folder is empty or not.
That's because you're actually counting the items (i.e., characters) of
the string "Macintosh HD:Photo_and_illu_html_files: files_in:". A path
string is not the same thing as a file reference, and AppleScript can't
know to do it for you given ambiguous context like this. Your script
wouldn't have worked in Mac OS 9, either -- this isn't a X-specific
thing.
There are several ways you could find out if the folder is empty:
tell application "Finder"
set the_vol to folder "Photo_and_illu_html_files" of the startup disk
-- or set the_vol to folder "Macintosh HD:Photo_and_illu_html_files"
set countfolder to folder "files_in" of the_vol
-- count the items and test vs. zero
set foldercount to count every item of countfolder -- the
Finder implicitly skips invisible items.
if foldercount > 0
end
-- or do it directly.
if some item of countfolder exists
end
end
If you use "list folder", you can bypass the Finder.
--Chris Nebel
AppleScript Engineering
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.