how do i test if an item is a 'file' or 'folder' ?

hello, i have a script that i’m building that loops through a directory and performs backups on specific folders (parts of the name have to match, if true, backup occurs)

my problem is that the script sometimes sees files that test true to my string matching (can’t avoid that)

is there anyway to test if an ‘item’ is a file, or folder?

here’s the beginning of my script:


repeat with i from 1 to the number of items in folder designRoot
		
		set thisItem to item i of folder designRoot
		set theName to the name of thisItem


i’d love to say something like:

if (thisItem isFolder) is true then
– do my processing
end if

i’m sure there is a way to do this but i can’t figure it out, i’ve been searching for a couple of days on this one.

any help would be appreciated so much!

thanks in advance

-dan

Hi Dan,

You could try:

if folder of (info for thisItem) is true then
-- Do something with folders, not files
end if

Best wishes

John M

if thisItem's class is folder then

wow you rock, thanks so much

never in a million years would i have guessed that:
if thisItem’s class is folder then

would actually compile (i’m new to applescript)

thanks again
-d

You might also consider a different approach:

tell application "Finder"
set folders2backup to every folder of folder designRoot whose name contains "blah"
duplicate folders2backup to disk "backup" -- or however you're backing up
end tell

Now, folders2backup will contain just the folders whose name contain the text string, meaning you don’t need to iterate through every item.

Hi,
I’m not sure, but it’s better to write “info for file”, no?

if folder of (info for file thisItem) is true then
-- Do something with folders, not files
end if

It really depends on the class of the incoming reference, Titanium.

As it stands, the ‘info for’ command seems to handle various forms of reference, such as:

So ‘info for someVariable’ works in the case of all the above forms. However, while ‘info for file someVariable’ works fine with a file path (a), it produces an error number -43 (file not found) with an alias (b) and a file specification (c).