Change File name / selectively

Hi everyone,

I’m trying to write this script to insert to my Automator workflow.

I want to rename a file named:

whatever_VAULT_20081203_SO.fcp

to:

whatever_VAULT.fcp

so I want to delete the string after “_VAULT”

All help will be appreciated.

Thanks
SB

set fileName to "whatever_VAULT_20081203_SO.fcp"

set beforeVault to item 1 of my asTID("VAULT", fileName)
set extName to item 2 of my asTID(".", fileName)
set newName to beforeVault & "VAULT" & "." & extName

on asTID(delimiter, textHere)
	set OLDtid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to delimiter
	set theItems to text items of textHere
	set AppleScript's text item delimiters to OLDtid
	return theItems
end asTID

or

set fileName to "whatever_VAULT_20081203_SO.fcp"

set newName to do shell script "echo " & quoted form of fileName & " | /usr/bin/ruby -e \"puts STDIN.read.scan(/(.*VAULT).*(\\..*)/).join('')\""

Thanks alot for the replies.

I hope one of them will solve my problem

:smiley:
SB