Page 1 of 1

CopyDirectory doesn't seem to work

Posted: Mon Jan 05, 2009 4:58 pm
by intern7

Code: Select all

OpenConsole()
   ClearConsole ()
;
;Print(temp$)
;PrintN("")
   PrintN ("Please stand by for SYSTEM BACKUP...")
   
   source$="c:\data\"
   destination$ = "e:\backup\" + FormatDate("%yyyy-%mm-%dd",Date()) + "\"
   
   Result = CopyDirectory(source$, destination$, "*.*", #PB_FileSystem_Recursive)
   
   If 0 = Result
      Print("Backup failed.")
   Else
      Print("Backup Succeeded.")
   EndIf
   
   PrintN("")
   Print ("Press ENTER to continue...>")
   Input ()

CloseConsole()
End
Only half of the source directory is being copied. Since the CopyDirectory isn't returning a 0 and thus thinks that it's finishing correctly and since only the first half of the source is being copied, the recursive algorithm that's implemented by the #PB_FileSystem_Recursive is likely not getting the second half of its initial recursive call.

It seems like it's a binary recursive algorithm that isn't following the second branch on the initial tree.

Posted: Mon Jan 05, 2009 5:35 pm
by Demivec
I can't verify this in x86.

I successfully duplicated a a directory structure with 3 sub-levels. (8 at level 1, 6 at level 2, 5 at level 3) for a total of a main directory and 19 sub-directories. There were 54 files distributed in those directories, some at each level. with no directories empty (all had a least one file in addition to sub-directories)

Posted: Mon Jan 05, 2009 6:00 pm
by intern7
Maybe it overflowed the bounds of some array or something. There's 1.19 GB of files in the main directory, 3,035 files in 205 subfolders.

I'm running it again now, to see how much is copied over.

Posted: Mon Jan 05, 2009 6:15 pm
by intern7
That's strange, I've been running it again and again here and sometimes it returns 0 and sometimes it doesn't. I can't figure out what the difference is -- there aren't try/catch statements that I can put in, are there?

Posted: Mon Jan 05, 2009 6:34 pm
by SFSxOI
hmmm...maybe this is related to something I noticed a few days ago. I was using the openfilerequester in some code to browse for and open a file when i found out that if the sub-directory was nested more then one deep it would fail on the file open. Then I found out the savefilerequester would fail also with sub-dir's more then one deep.

Code: Select all

If the dir structure was this:

C:\file.txt < this would work fine

C:\mydir\file.txt   < this would work fine

C:\mydir\nextdir\file.txt <this would work fine

C:\mydir\nextdir\anotherdir\file.txt < this would fail
I'm not sure if the limitation was with the rest of my code or what. This thread just reminded me of this.

Posted: Mon Jan 05, 2009 8:24 pm
by rsts
Worked fine here
4.42 GB
2432 files
95 folders
4 levels deep

Vista 64 @ 32 bit compiler

cheers

Posted: Mon Jan 05, 2009 11:39 pm
by intern7
Are you all using the code the same way that I was? There wsan't anything intrinsically wrong with the initial code, something that I missed?

Posted: Mon Jan 05, 2009 11:59 pm
by rsts
The only thing I changed was the actual directory I was copying.

cheers

Posted: Tue Jan 06, 2009 12:15 am
by Demivec
intern7 wrote:Are you all using the code the same way that I was? There wsan't anything intrinsically wrong with the initial code, something that I missed?
I used the same code, changing only the directories. I should be noted that when I ran the firsts few tests I always obtained results of "0". I changed the destination name so that it didn't include the FormatDate() portion. It worked after making that change. Then, after it worked once, I added it back in. I never obtained a "0" for the result of the Copy afterwards.

Posted: Tue Jan 06, 2009 1:24 pm
by yrreti
Interesting little program. I also got the same results as Demivec.
When I ran it with FormatDate("%yyyy-%mm-%dd",Date()) + "\" the first time, it failed.
I removed that part, and it succeeded. I added it back in and it always succeeded again and again.
Okay here is what I found when I tried your code.
The reason it succeeded is that the destination directory already existed. It got created when you ran
it without that FormatDate code. If you delete that directory and try to run using the formatDate code it
will again always fail. But if you manually just make the directory using explorer, it will work fine.
I believe this is a bug, because for some reason, adding The FormatDate part prevents the creating of
the initial main directory, and it shouldn't. It doesn't affect any sub directories.
So the way to fix your program is to first create the main directory, and then it will work fine every time.
The directory that I used for testing had several nested subs and files.