Script to trim files

Hello,

I would like to remove a “P” from every file that I have in one folder. I don’t need a complicated script with lots of questions, just a simple script that trims the first letter (character) of files in a folder that I can specify.

Any help is appreciated.

Thanks,
Agi

Model: G5
AppleScript: 2.1
Browser: Firefox 1.0.4
Operating System: Mac OS X (10.4)

OS X comes with a script that does this:

/Library/Scripts/Finder Scripts/Trim File Names.scpt

Ah, the dreaded Apple Trim File Name script :lol:


set MasterFolder to choose folder with prompt "Select the folder of filenames to trim"

tell application "Finder"
set FolderContents to files of folder MasterFolder
end tell

repeat with thisFile in FolderContents
	set thisFilesName to name of thisFile
	
	if the first character of thisFilesName is "p" then
		set Charcount to count characters of thisFilesName
		set newName to characters 2 thru Charcount of thisFilesName as string
		set name of thisFile to newName
	end if
	
end repeat

That one changes the filenames if the first letter is “p”


set MasterFolder to choose folder with prompt "Select the folder of filenames to trim"

tell application "Finder"
set FolderContents to files of folder MasterFolder
end tell

repeat with thisFile in FolderContents
	set thisFilesName to name of thisFile
	
	
	set Charcount to count characters of thisFilesName
	set newName to characters 2 thru Charcount of thisFilesName as string
	set name of thisFile to newName
	
end repeat

That one strips the first character no matter what it is.

SC

Or - for a couple of shorter/faster alternatives…

Trim first character from all names:

set f to choose folder with prompt "Choose a folder with filenames to trim"
tell application "Finder" to repeat with i in (get f's files)
	tell i to set name to text 2 thru -1 of (get name)
end repeat

Trim leading “p” from all names:

set f to choose folder with prompt "Choose a folder with filenames to trim"
tell application "Finder" to repeat with i in (get f's files whose name begins with "p")
	tell i to set name to text 2 thru -1 of (get name)
end repeat