realbasic-nug
[Top] [All Lists]

Re: Copying a folder

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Copying a folder
From: Austin Clow <dr_clow at mac dot com>
Date: Sat, 31 Jul 2004 15:26:43 -0500
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <S dot 0000334500 at mail dot tempel dot org>
Not nonsense, if he says j.count it is recalculated on each loop (for i=1 to j.count). So if he was moving or deleting the files during the loop the the count would slowly diminish to zerro. Also, recalculating takes time, much longer than assigning it to a variable, "c" in this case, and saying for i=1 to c.

And you must not rely on Count anyways, since in the loop some
other process could change the number of items in the dir and
then you'd go wrong, again. The safest way is to loop until f becomes
nil.


Which is exactly what is just said. If he moves files/deletes them during the loop it will diminish. I was advising him on the "for i=1 to f.count" not on the statement of infinite loops (as I previously was). Sorry for all the confusion.

- Austin Clow


On Jul 31, 2004, at 3:14 PM, Thomas Tempelmann wrote:

Austin Clow wrote:

you need to use

dim i,c as integer
dim j as FolderItem
c=j.count


//if you are moving the files from the folder j then you need to use

for i=1 to c
f=item(1)
next

the reason for this is because if you move the item out of the folder
"j" then the item will be gone and the count will no longer be equal to
the first time you said count it will get smaller each time it passes
through the loop.

Nonsense. If he'd really move the files (or delete them) yours
is not better than doing

   for i=1 to j.count

In both cases, you'd end up skipping some items.

And you must not rely on Count anyways, since in the loop some
other process could change the number of items in the dir and
then you'd go wrong, again. The safest way is to loop until f becomes
nil.

And to answer Andrew's original question:

Andrew, if you look at a "f" var that you've previously
gotten using j.Item(idx), then it'll never be an Alias,
because Item() would have already followed (resolved) the
alias. Instead, you must make sure you're always using
TrueItem in the loop. Then you'll get items that can be
an Alias, so you can skip them.

Thomas


--
Thomas Tempelmann,
http://www.tempel.org/rb/
http://www.tempel.org/software/


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>