• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Renaming Files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Renaming Files


  • Subject: Re: Renaming Files
  • From: "Marc K. Myers" <email@hidden>
  • Date: Fri, 27 Jul 2001 09:00:00 -0400
  • Organization: [very little]

> Date: Thu, 26 Jul 2001 21:36:41 -0400
> To: email@hidden
> From: "M. H. Griffiths" <email@hidden>
> Subject: Renaming Files
>
> I have what I hope is a simple question:
>
> I want to be able to take SimpleText pictures and convert their file
> names to include a suffix (.PICT, .GIF, .JPEG) so they can be readily
> uploaded for use in a web page. I am trying to figure out how I can
> do the entire folder in one script. So far I am not having much
> luck. Any ideas?
>
> Thanks

Do you want to add each file's file type as a suffix to the file's name?
This script will do that:

set theFldr to (choose folder with prompt "Pick a folder to process:")
tell application "Finder"
set theFiles to (files of theFldr) as alias list
end tell
repeat with aFile in theFiles
set theFile to (contents of aFile)
set theInfo to info for theFile

-- crop the file type by removing spaces
set theType to file type of theInfo
set AppleScript's text item delimiters to {" "}
set theType to text items of theType
set AppleScript's text item delimiters to {""}
set theType to (theType as text)

set theName to name of theInfo

-- crop the name to allow for max of 31 characters
set maxLng to 30 - (length of theType)
if length of theName > maxLng then
set theName to (characters 1 thru maxLng of theName) as text
end if

set theName to theName & "." & theType
tell application "Finder" to set name of theFile to theName
end repeat


If you just want to tack on a fixed extension, it could work like this:

set theFldr to (choose folder with prompt "Pick a folder to process:")
tell application "Finder"
set theFiles to (files of theFldr) as alias list
end tell
set theExt to button returned of (display dialog "Which extension do " & [optn-L]
"you want to add?" buttons {".JPEG", ".GIF", ".PICT"})
repeat with aFile in theFiles
set theFile to (contents of aFile)
set theName to name of (info for theFile)
set maxLng to 31 - (length of theExt)
if length of theName > maxLng then
set theName to (characters 1 thru maxLng of theName) as text
end if
set theName to theName & theExt
tell application "Finder" to set name of theFile to theName
end repeat

NOTE: Where you see "[optn-L]", substitute the AppleScript continuation character.

Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074

[7/27/01 8:58:16 AM]


  • Prev by Date: scripting icon's
  • Next by Date: Re: (OFF) What Ever Happened To OpenDoc?
  • Previous by thread: Re: Renaming Files
  • Next by thread: Re: Renaming Files
  • Index(es):
    • Date
    • Thread