file suffixes

hi
can someone please tell me how to select files by suffix (or last 4 characters). I know how to do it based on prefix but can’t find any info on suffixes.

What I want to do is send .pdf and .eps files to separate folders “on adding folder items etc etc”

I guess that I would have to just search on the string? pdf and eps will never occur in front of the . in the file name if that makes it easier
thanks!!

You could find the files with:

set FolderPath to “” – define the folder

tell application “Finder”
activate
set PDFFiles to every file in alias FolderPath whose name ends with “.pdf”
end tell

Hi :slight_smile:

Another way…

In dictionnary of Finder :

name extension Unicode text [r/o] – the name extension of the item (such as ?txt?)

Suggestion :

tell application "Finder"
	activate
	set TheFolder to (choose folder)
	set PdfDoc to every item of TheFolder whose name extension is "pdf"
	set EpsDoc to every item of TheFolder whose name extension is "eps"
end tell

Or only the name of the items :

tell application "Finder"
	activate
	set TheFolder to (choose folder)
	set PdfDoc to name of every item of TheFolder whose name extension is "pdf"
	set EpsDoc to name of every item of TheFolder whose name extension is "eps"
end tell

:wink:

Fredo,

When i look in the Finder dictionary, i can’t find name extension.
My Finderversion is 9.0.4. Has this been added later on?

Jan

Hi :slight_smile:

Oh sorry, this syantaxe is adapted for MacOsX.

For MacOs9 you can use the “file type” information of files, for exemple :

tell application "Finder" 
   activate 
   set TheFolder to (choose folder) 
   set PdfDoc to every item of TheFolder whose file type is "PDF " 
   set EpsDoc to every item of TheFolder whose file type is "EPSF" 
end tell

Attention, it is absolutely necessary to respect the upercase and lowercase characters
in “file type” information. To know this information, uses this simple script:

tell application "Finder" to return file type of (choose file)

:rolleyes: