Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fso.CopyFolder

Status
Not open for further replies.

Error7

Programmer
Jul 5, 2002
656
0
16
GB
If I set the switch to FALSE i.e. fso.CopyFolder ListFolders.List(i), DriveLetter, FALSE - it doesn't copy newer files if the folder already exists on the receiving drive.
Is there a way round this?

[gray]Experience is something you don't get until just after you need it.[/gray]
 
overwrite Optional. Boolean value that indicates if existing folders are to be overwritten. If True, files are overwritten; if False, they are not. The default is True.
 
That is the problem. Not only does it not overwite existing folders, it doesn't copy new files from source to destination into an existing folder.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
@mintjulep a list of folders and sub folders to be copied from the source drive.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Ok, so my point is that what you are seeing is the documented behaviour. If you want to copy over the files, then you need TRUE.

But it is beginning to sound to me like you are trying to use CopyFolder (and the underlying API call it wraps) in a way that it was not intended: are you trying to only copy files that are newer than matching file in the destination (i.e if source file is older than a file in the destination you do not want to overwrite it)?
 
@strongm are you trying to only copy files that are newer than matching file in the destination (i.e if source file is older than a file in the destination you do not want to overwrite it)?
Yes, that is exactly what I was hoping to achieve by using CopyFolder. But now that I realise that CopyFolder doesn't copy a folder if it already exists on the destination drive, even if that folder is empty, I have had to resort to FileCopy, checking for a match in the file sizes to determine if it should be overwritten or not.


[gray]Experience is something you don't get until just after you need it.[/gray]
 
> CopyFolder doesn't copy a folder if it already exists on the destination drive, even if that folder is empty

You are starting to confuse me! Yes, yes it does - IF the flag is set to True. It won't if the flag is False, as the documentation clearly states. But it does not ever check the datetimestamp of files under any circumstances (and never indicates it will!) - it either ov erwrites the file (True) or it fails (false)

The more sophisticated behaviour you want is not supported by any part of the FSO, not any API, or built-in library (that I am aware of). Particularly as you now seem to have suggested you are also concerned about "a match in the file sizes to determine if it should be overwritten or not"

But you could try RoboCopy instead; it's a sophisticated file copying/archiving commandline utility that used to be a separate download, but has been bundled with the OS since Vista, and the following will deal with your requirement concerning newer files (but there are additional flags available to allow it to deal with file sizes and other attributes as well):

Code:
[COLOR=blue]Shell "robocopy " & ListFolders.List(i) & " D:\ /XO /S"[/color]

 
Mike, let me try to explain myself better:
C:\Folder\video\File1 - CopyFolder C:\Video\File1, D:\, False
C:\Folder\Video\File2 - CopyFolder C:\Video\File2, D:\, False
C:\Folder\Video\File3 - CopyFolder C:\Video\File3, D:\, False

If the folder D:\Video exists on the destination drive but that folder is empty, it doesn't copy any files contained in C:\Folder\Video\

Thanks for the heads up on Robocopy, I'll investigate that.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
I wouldn't expect any of those to work at all, no matter what the flag is set to, since CopyFolder requires a folder path as a parameter, not a file path!

But to be clear, I completely understood what you were trying to tell me earlier about this behaviour - I'm just pointing out that it is exactly as expected from the documentation. In essence, whilst copying CopyFolder treats a folder exactly the same way it consequently treats files in that folder: as per the documentation, if it already exists it won't overwrite it at all (whether empty or not) if the flag is False. And what it does in that circumstance is raise an error (File Already Exists), and immediately stops CopyFolder. And since it has stopped, we never get to the point of trying to copy files into the folder that stopped it running. And this should be the case whether the existing destination folder is empty or not

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top