Re: renaming files in Finder
Re: renaming files in Finder
- Subject: Re: renaming files in Finder
- From: Nigel Garvey <email@hidden>
- Date: Tue, 5 Feb 2002 12:40:00 +0000
Deivy Petrescu wrote on Mon, 4 Feb 2002 17:56:43 -0500:
>
At 22:28 +0000 2/4/02, Mr Tea wrote:
>
>This from Stephen Swift
>
>>Wouldn't this be a much easier approach?
>
>>
>
>>on run
>
>> set myFolder to choose folder
>
>> --asks you what folder
>
>> tell application "Finder"
>
>> repeat with x in every file of myFolder
>
>> set name of x to ("temp " & name of x)
>
>> end repeat
>
>> --adds "temp" to all file names in myFolder
>
>> end tell
>
>>end run
>
>
>
>Easier, perhaps, but no more effective on my OS 10.1.2 with AS 1.8.2b.
>
>The Finder likes it better if the files in the folder are put into a
>
>variable first...
>
>
Actually, I think it likes only if the files are in a variable. It
>
does not work any other way.
>
And I am talking about AS 1.8.1
This is a recurring topic. 'Every file of myFolder' is a Finder reference
to all the files in the folder generally. It looks like a list when
quizzed, but it's not in itself a fixed list of the individual entities.
If the commands inside the repeat do anything to change the number of
files in the folder, or the Finder's opinion of their order in it, the
reference will imply a slightly different "list" on each iteration.
>
>set myFolder to choose folder
>
>tell application "Finder"
>
> activate
>
> set theFiles to every file of myFolder
>
> repeat with x in theFiles
This works because the 'set' line uses the reference form to make an
AppleScript list -effectually taking a snapshot of the folder's files at
that instant - and the repeat loops through that. Unless the repeat
deletes the folder itself or does something silly to one of the files
later in the list, it's unlikely that there'll be any confusion after
that. You can dispense with the named variable by using 'get' and its
result:
get every file of myFolder
repeat with x in the result
... or:
repeat with x in (get every file of myFolder)
This seems to work too, though I'm not quite clear why it should:
repeat with x in (every file of myFolder) as list
NG