I have 9 files in the c:\temp\dp folder I am trying to move to c:\temp\archive but only 5 out of the 10 move. This is all part of a bigger project that ftps these files and moves them upon successful transfer. I haven’t found a post that helps and I’m not sure what I’m doing wrong, here’s the code:
Var file, localFolder, archiveFolder As FolderItem
Don’t have localFolder.Count in your For loop. It changes during execution as you move files.
Also:
when you post code, please do this:
a) put the code in your post
b) Select it all with the mouse
c) Click on </>
You might do better with:
while (localFolder.Count>0)
file = localFolder.ChildAt(0)
if (file<>Nil) then file.MoveTo (archiveFiolder)
wend
except that calculating .Count every time round the loop might be expensive.
So what about:
Var i, lim as Integer
lim = localFolder.Count - 1
For i = lim Downto 0
file = localFolder.ChildAt(0) // The 0 is deliberate
If file <> Nil Then file.MoveTo(archiveFolder)
next
ii = localFolder.Count
MessageBox(“count=” + str(ii))
while (ii > 0)
file=localFolder.ChildAt(ii-1)
if (file<>Nil) then
file.MoveTo(archiveFolder)
end if
ii = ii - 1
wend
If for some reason, ChildAt(0) failed to move, the entire operation would fail because you’re trying to move the same unmovable file ii number of times.
Of course you are right. I haven’t caught up to the new mechanisms. At this point it comes down to how the OP wants to handle an error, via Try…Catch or Exception.