Move script fails with only one file

Hi there,

This (small part) of a script is giving me a headache.
It creates a subfolder and than moves the content of the folder to the subfolder.
No rocket-science so far. But now comes the strange thing.
The script fails when there is only one file in the folder???

More then one file and it works like a charm.

What am I doing wrong?

Help me please !!!
Erwin


on open draggedItems
	repeat with oneFolder in draggedItems
		set hoofdMap to oneFolder as string
		set subMap to hoofdMap & "aangeleverd:"

		tell application "Finder"
			try
				make new folder at (hoofdMap as alias) with properties {name:"aangeleverd"}
			on error
				display dialog "De map 'aangeleverd' bestaat al!"
			end try
					
			set theFiles to every file of entire contents of (hoofdMap as alias)
			repeat with aFile in theFiles
				set fileToCopy to hoofdMap & (name of aFile)
				set destinationFolder to subMap
				move fileToCopy to destinationFolder
			end repeat
		end tell
	end repeat
end open

Hi,

if there is a single file, every file returns a single file specifier instead of a list
Coerce it explicitly to list

set theFiles to (every file of entire contents of oneFolder) as list

You could also move all files with one line

on open draggedItems
	repeat with oneFolder in draggedItems
		tell application "Finder"
			try
				make new folder at oneFolder with properties {name:"aangeleverd"}
			on error
				display dialog "De map 'aangeleverd' bestaat al!"
			end try
			
			move (every file of entire contents of oneFolder) to folder "aangeleverd" of oneFolder
		end tell
	end repeat
end open

Thanks Stefan

Just what the doctor ordered !!!
I didn’t know about the every file exception.