Move\Copy Files with\without override

Posted on 2003-12-08
Last Modified: 2010-05-18
What different methods are available ?

Thank You
Question by:AlexF777
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
LVL 33

Accepted Solution

hongjun earned 125 total points
ID: 9898483
try this
include "Microsoft Scripting Runtime" from project-references

Dim fso As FileSystemObject

Set fso = New FileSystemObject
fso.CopyFile "c:\sourcefile.txt", "c:\destination.txt", False
fso.MoveFile "c:\sourcefile.txt", "c:\destination.txt"

Set fso = Nothing

LVL 33

Expert Comment

ID: 9898489
' false means do not override
' true means override
fso.CopyFile "c:\sourcefile.txt", "c:\destination.txt", False

LVL 33

Expert Comment

ID: 9898493
to check if file exists, do this

If fso.FileExists("c:\myfile.txt") Then
    MsgBox "File Exist"
End If

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 33

Expert Comment

ID: 9904535
Thanks for selecting my comment as the answer. But why the grade of "B"? It could have been an A grade since my comment solved your problem directly. Note that a grade A given does not differ from a grade B or C to a questionner. It will not affect your question points value but rather it only affect your grading record. Your grading record will be better if you shows consistent A grading awarding habit.

Please see Tip #11 - Grade quickly and fairly

Please explain the reason for the B grade.


Author Comment

ID: 9909466
Ok, what I am trying to accomplish is to override destination files if they already exist ( would be nice to be able
to use wild-cards too ).

fso.CopyFile will do it but only if destination is not read-only, fso.MoveFile -will not do it at all.

may be I am wrong ?


LVL 33

Expert Comment

ID: 9909474
Perhaps you try using Shell api


Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to compare ms sql hashbytes results within vb6 5 108
Hide vba in gp 7 127
VBA - If Bookmark = "XXBOOKMARKXX" then 15 67
Problem to line 23 81
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question