Link to home
Start Free TrialLog in
Avatar of Andrew Angell
Andrew AngellFlag for United States of America

asked on

FileSystemObject...need to overwrite existing files in this simple image mover script.

I've got this very basic script setup...

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim FTPPath
FTPPath = "C:\Websites\cay3\image_ftp\"

Dim DestPath
DestPath = "C:\Websites\cay3\products\"

For Each objFile In objFSO.GetFolder(FTPPath).Files
    objFile.Move DestPath

Set objFSO = Nothing

This works great except that I get errors when the file already exists.  I need it to just overwrite.  I see an overwrite option when creating new files, but I don't see how to add the option when simply moving files.  Any info would be great.  Thanks!
Avatar of OverSeer
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andrew Angell


Ok, it's been awhile since I've had to mess with this stuff and I'm having some trouble.  I tried changing it to:

For Each objFile In objFSO.GetFolder(FTPPath).Files
     objFile.CopyFile FTPPath, DestPath, true

But I'm getting an error that Object doesn't support this property or method.
i'm a little confused, too, about the fact that the code I currently that, which does work except for the overwrite problem, uses objFile.Move when the tutorial you sent me shows obj.MoveFile...???
Oh, I'm not saying you can't use Obj.Move.  It's just that Obj.Move doesn't have the capability to overwrite whereas Obj.Copy does.