testing if a finder item is a file or folder

im working on a backup script that needs to be able to process files and subfolders in a given folder differently (eg sync the files and look in the folders for files to sync).
the problem is, given the path of an item, how does one test whether it is a file or a folder?

There are at least two ways that I know of. If you have a string with the file path in it then you can check for the last character of the string. If that is a colon then the path is a folder, for a POSIX path it would be a back slash I think. The other way would be to use the Finder properties. Here the class of an item is “folder” or “document file”. You could also set up your calls to the finder to filter them into separate lists like this:

set thePath to (path to desktop)
tell application "Finder"
	set theFolders to every folder of thePath as alias list
	set TheFiles to every file of thePath as alias list
end tell

thanks, for the help. I worked out the following code which does just what i need.


set thePath to (path to desktop)
tell application "Finder" to get kind of thePath

Note that kind is dependent on the current system language.

A more reliable way is the info for command that is in StandardAdditions:

set thePath to (path to desktop)
set {folder:thePathIsFolder} to info for thePath

thePathIsFolder --> Check the result in Script Editor