• 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: Using 'Repeat'
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using 'Repeat'


  • Subject: Re: Using 'Repeat'
  • From: "Christopher C. Stone" <email@hidden>
  • Date: Sun, 25 Mar 2001 06:47:00 -0600

Hello Peter,

At 03/25/2001 17:12 +1000, email@hidden wrought:

> What I am trying to do is move any number of files with similar names to a
> new folder.
>
> tell application "Finder"
> set test_folder to "Macintosh HD:test folder:"
> set test_folder2 to "Macintosh HD:test folder2:"
>
> set file_list to list folder test_folder
> set search_term to "376"
>
> repeat with an_item in file_list
> if an_item contains search_term then
> move file an_item to test_folder2
> end if
> end repeat
> end tell

You're running into a couple of problems here

1) List Folder only returns a *name* list of items in a folder.

File names are useless in terms of referencing an item to be moved.
You need file specs or aliases.


2) The Repeat form above uses a "Reference" to "an_item"

set f to "minerva:storage:"

set l to list folder f

repeat with ndx in l
ndx
end repeat
____

On Iteration 1 the ndx variable is:

item 1 of {"Desktop Pictures", "Editing Tools", "Favorites.html", "OneClick Library Files", "Sand - Espy 12 by ccs", "Sand.orig", "System 9.1 & Finder & Resou.img"}

To get what you're after you need to de-reference the item:

repeat with ndx in l
set x to (contents of ndx)
end repeat
____

The way I'd probably go about your test task is:

---------------------------------------------------------------------------
set srcFld to alias "Black Hole:Test Src:"
set destFld to alias "Black Hole:Test Dest:"

tell application "Finder"

set {nmList, fileList} to {name of items of srcFld, items of srcFld}

repeat with ndx from 1 to count of nmList
if (item ndx of nmList) contains "645" then
move item ndx of fileList to destFld
end if
end repeat

end tell
---------------------------------------------------------------------------

This form is a little faster than the reference form.

If I were likely to move more than one item I'd build a list of tham and then move all at once.

---------------------------------------------------------------------------
set mvList to {}
set srcFld to alias "Black Hole:Test Src:"
set destFld to alias "Black Hole:Test Dest:"

tell application "Finder"

set {nmList, fileList} to {name of items of srcFld, items of srcFld}

repeat with ndx from 1 to count of nmList
if (item ndx of nmList) contains "645" then
set end of mvList to item ndx of fileList
end if
end repeat

if (count of mvList) > 0 then
move mvList to destFld
end if

end tell
---------------------------------------------------------------------------

Oh, although Whose clauses are problematic at times, they work very well for some tasks:

---------------------------------------------------------------------------
set srcFld to alias "Black Hole:Test Src:"
set destFld to alias "Black Hole:Test Dest:"

tell application "Finder"
move (every item of srcFld whose name contains "645") to destFld
end tell
---------------------------------------------------------------------------



--
Best Regards,

Christopher Stone
______________________________
StoneWorks Computer Consulting
email@hidden


References: 
 >Using 'Repeat' (From: email@hidden)

  • Prev by Date: [OT]OS X Anybody got a clue how to tell iTunes to use my existing music folder?
  • Next by Date: Re: CGIs with OSX
  • Previous by thread: Using 'Repeat'
  • Next by thread: Re: Using 'Repeat'
  • Index(es):
    • Date
    • Thread