Re: referencing the last item in a list
Re: referencing the last item in a list
- Subject: Re: referencing the last item in a list
- From: "Marc K. Myers" <email@hidden>
- Date: Tue, 16 Jul 2002 17:45:05 -0400
- Organization: [very little]
>
To: email@hidden
>
Subject: referencing the last item in a list
>
From: email@hidden
>
Date: Tue, 16 Jul 2002 10:46:59 -0700
>
>
i am trying to create a script that will allow me to process a list of
>
images from one folder to another, renaming them beginning after the last
>
number. the destination folder will have images with a prefix then four
>
digits...ie FOTO0021.jpg, how can i reference this so that it starts
>
renameing beginning with the next number?
>
>
so to recap, i want to be able to move the files from one folder to
>
another and rename them beginning with the next number. can anyone help me
>
with this? thanks,
>
matthew
set listXYZ to {"Z", "Y", "X"}
set lastItem to last item of listXYZ
--> "X"
Unfortunately, what you want isn't the last item of a list. What you
want is the last item of a *sorted* list. There are all kinds of
sorting algorithms but it's a lot easier to use the Akua Sweets
scripting addition:
set listXYZ to {"Z", "Y", "X"}
set lastItem to last item of (order list listXYZ)
--> "Z"
To extract the last name and increment the numeric part you could do
something like this:
set theFldr to (choose folder)
tell application "Finder" to set nameList to name of files of theFldr
set nameList to order list nameList
set lastItem to last item of nameList
try
set theSeq to ((text 5 thru 8 of lastItem) as integer) + 1
set newName to "FOTO" & text -4 thru -1 of ("000" & (theSeq as
text)) & ".jpg"
end try
--> "FOTO0046.jpg"
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[7/16/02 5:43:10 PM]
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.