Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Use FileSystemObject to overwrite existing files.
Message
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00402001
Message ID:
00402062
Views:
14
>I'm using the following code to iterate through files in a folder and copy or move them based on certain properties of the files:
>
Dim oFso As New Scripting.FileSystemObject, oFile As Scripting.File
>For Each oFile In oFso.GetFolder(lcFolder).Files
>   'oFile.Copy or oFile.Move here
>Next
>Why is that this works:
>
oFile.Copy (lcDestination1)
>but this does not:
>
oFile.Copy (lcDestination1,True
Try oFile.Copy lcDestination1, True

>and how do I get oFile.Move to overwrite files?
>

You don't; Move simply changes which folder has the file entry in it; no actual copying takes place. It can't move a file or folder name in conflict with an existing fole or folder name in the destination. The FSO's MoveFile docs method discuss the situation in some detail; File.Move is doing the same thing as the FSO.MoveFile method, except it takes it's source as the current object.

If you want to Move something, you have to ensure the name is not already in use in the target folder; the docs are very explicit.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform