Changing a filename

I did search, with little success, but I am not figuring this out.
I am trying to find away to count back 7 characters from the end of a file name and then omit those text items, and then replace with .pdf.

For example:
Before filename: xxxxxxxxx000.pdf
After filename: xxxxxxxxx.pdf

or
Before filename: xxxx120.pdf
After filename: xxxx.pdf

Reason being: This is the final stage on a folder action script that is working off a filename created by someone scanning in a document. The scanner always appends a 3 digit number & “.pdf” to the end. I am actually just looking for a way to remove the 3 digit number appended before the “.pdf”

I am not sure why I just can’t count backwards on a character filename? I know this is wrong, but I don’t know why?


tell application "Finder"
	try
		set kFiles to every file of folder new_folder
		repeat with currFile in kFiles
			set thisName to name of currFile
			set temp_filename to thisName
			delete (text items -1 through -7 of temp_filename)
			--display dialog new_name as string
			set name of currFile to new_name
		end repeat
	end try
end tell

Hi Jeff,

if the extension is always pdf, then this should do it


tell application "Finder"
	try
		set kFiles to every file of folder new_folder
		repeat with currFile in kFiles
			set name of contents of currFile to (text 1 thru -8 of (get name of currFile) & ".pdf")
		end repeat
	end try
end tell

Stefan,
If you only knew how much time I spent going around this is so many wrong ways. What you gave me is exactly what I was looking for.

Many thanks again.

-jeff