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.
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)
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?
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.
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.
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.
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.