Copy vs Move Problem 
Author Message
 Copy vs Move Problem

People,

The following code produces unexpected results.

   Source=getfolderItem("Dinsdale:Logs")
   DestinationStore=getfolderItem("Dinsdale:Logstore")
   For i=1 to source.count //go through each item in the folder
     file=source.item(i)
     if file<>Nil then
       If file.exists and
file.CreationDate.Shortdate=Yesterday.Shortdate then //it's created
yesterday
         //file.copyfileto DestinationStore  //it's a file so copy it
         file.moveFileTo destinationStore
       end if
     end if
   next

If I use the copyfileto line, all the relevant files are copied. If I
use the movefileto line, only one file is copied. A rerun of the code
will copy another file. So why won't movefileto move all the selected files?

Thanks

Andrew



Fri, 09 Sep 2005 09:02:37 GMT  
 Copy vs Move Problem

Quote:

> People,

> The following code produces unexpected results.

>    Source=getfolderItem("Dinsdale:Logs")
>    DestinationStore=getfolderItem("Dinsdale:Logstore")
>    For i=1 to source.count //go through each item in the folder
>      file=source.item(i)
>      if file<>Nil then
>        If file.exists and
> file.CreationDate.Shortdate=Yesterday.Shortdate then //it's created
> yesterday
>          //file.copyfileto DestinationStore  //it's a file so copy it
>          file.moveFileTo destinationStore
>        end if
>      end if
>    next

> If I use the copyfileto line, all the relevant files are copied. If I
> use the movefileto line, only one file is copied. A rerun of the code
> will copy another file. So why won't movefileto move all the selected files?

Because 'source.count' gets reevaluated everytime around the loop while
'i' keeps getting incremented by 1.  Consider...

A directory with two items (source.count = 2), first time through the
loop i is 1 and you move the first file.  On the next iteration, i goes
to 2 but source.count is now 1 so the loop terminates and you've only
moved one file.

Change your for loop to "for i = source.count downto 1'

--
PGP Key (DH/DSS): http://www.shimkus.com/public_key.asc
PGP Fingerprint:  89B4 52DA CF10 EE03 02AD  9134 21C6 2A68 CE52 EE1A



Fri, 09 Sep 2005 09:12:28 GMT  
 Copy vs Move Problem
Hi Andrew,

Quote:
> If I use the copyfileto line, all the relevant files are copied. If I
> use the movefileto line, only one file is copied. A rerun of the code
> will copy another file. So why won't movefileto move all the selected files?

I'm guessing that it's because you are moving the files out of the
directory while you are trying to iterate through that directory.
Perhaps if you indexed through your directory and shoved the
FolderItem's that need to be moved into an array first, and then
iterated through that array, doing the moves, it would work.

--gordy



Fri, 09 Sep 2005 09:18:21 GMT  
 Copy vs Move Problem
Joe,

The problem is that this give rise to a syntax error. Can't for the life
of me see why as the help files indicate that it should work. But now
there are larger problems. I have several of these loops each doing
something different, but after the first one, each loop is only
iterating once. And it seems to be intermittent. Will keep on trying
though - probably a coding problem.

Andrew

Quote:

> Change your for loop to "for i = source.count downto 1'



Sat, 10 Sep 2005 13:51:03 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Group level move vs sub-group level move.

2. 64bit MMX Memory copy vs 32bit nonMMX copy

3. shallow copy vs. deep copy

4. VS File copying problem --Protection Violation !

5. 64bit mem copy/move

6. copying (moving) large files to remote server ...

7. copy and move files

8. MOVE VS CMOVE

9. Propprint:Copies vs Dot-matrix printer

10. Question on VS COBOL II copy and replacing

11. References vs copies w/ *x

12. References vs Object Copying

 

 
Powered by phpBB® Forum Software