Routine for getting items in a folder

I’m making a droplet to move ‘files inside a folder’ to a new location by dropping the folder that contains them onto The droplet. I did it easily in 9. Not the same in X.
I need the routine for returning the files in a given folder-
SC:D

Browser: Internet Explorer 5.17
Operating System: Mac OS X (10.1.x)

I’m not sure how you expected to do it in Mac OS 9.x, but this hasn’t changed:

tell application "Finder"
  set myFiles to every file of folder "Path:to:folder:"
end tell

with this clunky piece of code:

(on open filelist)
tell application “Finder”
set SourceFold to selection
set FolderPath to (item 1 of SourceFold) as string
set ref2folder to folder FolderPath
set filelist to (items of ref2folder) as list
end tell

(end open)

I used this because it’s part of a droplet to ‘process a selection of dropped files’, or the ‘files in a folder’, so either could be sent to the same handler with the name “filelist”. “every item of filelist” was yeilding the path of the folder, not the items.
SC

This is not appropriate for a droplet.

The definition of a droplet is that it should react to the items that were dropped on it. This script completely ignores whatever was dropped, instead focussing on whatever is selected which might not be the same thing.

A better way of dealing with this would be to make the script react differently depending on how it was called. For example, this script counts the number of items in a folder. It can be used as a droplet where you drop a folder on the script (with error checking to make sure you do drop a folder and not a file), and it also runs as a regular script so you can double-click it and it will prompt for a folder to use. Both the open and run handlers call the same ‘work’ handler so you know you’ll get the same results no matter which way you invoke the script.

on open (droppedItems)
	-- this is called when something is dropped on the script's icon
	
	-- ignore anthing but the first item dropped
	set theFolder to first item of droppedItems
	-- make sure it's a folder
	if folder of (info for theFolder) is true then
		doit(theFolder)
	else
		display dialog "Oops. didn't drop a folder!" buttons {"doh!"}
	end if
end open

on run
	-- this is called if the script is double-clicked
	
	set theFolder to (choose folder)
	doit(theFolder)
end run

on doit(theFolder)
	-- here's where we do the work
	tell application "Finder"
		set filelist to (items of theFolder)
		display dialog "There are " & (count filelist) & " items in " & theFolder as text
	end tell
end doit

set SourceFold to selection
“not appropriate for droplet”

I noticed that when I wrote the script, and it caught my eye. I copied that portion from a sample script, so that’s how it ended up there. I wonder about its appropriateness, because when you drop a folder, it is the current selection of the Finder, which is why I’m assuming it works.

tell application "Finder"
set myFiles to every file of folder "Path:to:folder:"
end tell

Returned "can’t get every file of ‘Path:to:folder:I:dropped’ "

	tell application "Finder"
		set myFiles to (list folder FoldR as list)
	end tell

Returned all the items in the folder in the form I was looking for. Comments about that?
SC

Browser: Internet Explorer 5.17
Operating System: Mac OS X (10.1.x)

Can’t explain that one off hand… I assume the path it displayed was correct for the folder you dropped, right?

‘list folder’ is a standard addition and therefore will work anywhere - it doesn’t need to be in a ‘tell app “Finder”’ block. Other than that, that’s a suitable alternative as long as you bear in mind you will only get back a list of file names, not actual file references or aliases. You’ll probably also want ‘without invisibles’ to suppress invisible/hidden files in the folder.

Browser: Safari 412
Operating System: Mac OS X (10.3.7)