Re: Renaming multiple files
Re: Renaming multiple files
- Subject: Re: Renaming multiple files
- From: "Mark J. Reed" <email@hidden>
- Date: Thu, 4 Dec 2008 09:46:30 -0500
On Thu, Dec 4, 2008 at 9:10 AM, Chris Page <email@hidden> wrote:
> tell application "Finder" to get files of folder "Input Files" of desktop
> returning folderItems
Just curious - does the use of "returning" differ in any meaningful
way from doing a "set"? It's a new one on me.
> set i to 1
> repeat with f in folderItems
I think it would be cleaner/clearer to use the index as the loop
control; then you don't need an explicit increment step inside the
loop:
repeat with i from 1 to count(folderItems)
set f to item i of folderItems
...
But reasonable people disagree on such matters. (I'm rather fond of
loop constructs that let you get both the index and the item at the
same time as part of the loop control, e.g. Enumerable#each_with_index
in Ruby, or PHP's foreach statement.)
> tell application "Finder" to move f to folder "Output Files" of desktop
> set the name of the result to (i as text) & ".xls"
The only potential problem here is that if a file with the original
name already exists in the output folder, it will be overwritten.
This may not be an issue in the particular case under discussion; if
not, great. If it is a concern, the safest thing (other than somehow
taking advantage of the POSIX rename(2) interface that lets you do it
all in one go, via e.g. Perl's rename() function or the shell's mv
command) would be to create a new, temporary, empty folder at the
start of the loop. Then move each item into the temp folder, rename it
there, and only then move it into the target folder.
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden