Re: Loops
Re: Loops
- Subject: Re: Loops
- From: m <email@hidden>
- Date: Sat, 2 Feb 2008 13:34:04 -0800
Thanks Ed,
It's funny how loops can be so tricky.
One trick I saw only the other day ( which I might have missed in all
the AS suggestions) is to iterate through a loop from 1 to x, but make
sure ( in moving files) always to move file 1.
On Feb 2, 2008, at 9:28 AM, Ed Stockly wrote:
repeat with x from y to 1 by -1 -- decrementing loop
That is probably the most reliable solution posted so far...
tell application "Finder"
repeat until (count files of somefolder) = 0
move (some file of somefolder) to someotherfolder
end repeat
end tell
This solution has a built in inefficiency, finder must count the
files in the folder in every repeat loop. This will slow thing down
dramatically when there are large numbers of files.
tell application "Finder" to move files of somefolder to
someotherfolder
Another fine solution, unless it is possible that there may be files
with the same name in the destination folder. A repeat loop allows
the scripter the opportunity to handle exceptions on a file-by-file
basis.
tell application "Finder"
set foo to every file of entire contents of path2sourcefolder"
move items of foo to path2Destinationfolder
end tell
This can be problematic. Entire contents mines down in the directory
and gets every file/item in folders within folders and the move
command dumps all into the same directory. If files in the sub-
folders have the same names the command would fail.
Another option would be :
set myFolder to path to documents folder
tell application "Finder"
set myFiles to every file of myFolder as alias list
repeat with thisFile in myFiles
try
--do your stuff here
on error errText number errNum
--handle files that can't copy here
----duplicates, in use, etc.
end try
end repeat
end tell
HTH,
ES
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (applescript-
email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to 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
References: | |
| >Re: Loops (From: Ed Stockly <email@hidden>) |