Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
How can I copy files, not overwrite existing
files, and not prompt?I see how to do this with overwriting but not
without.

What are you trying to do?
If you are trying to copy a file into a folder where a file of the same name already exists you have to choices. Either overwrite the existing file or abort the copy and do nothing. You cannot have two files with the same name in the same folder.
Without the prompt you WILL ovrwrite the exisitng file which is probably what you dont want.
Stuart

What are you trying to do?
If you are trying to copy a file into a folder where a file of the same name already exists you have to choices. Either overwrite the existing file or abort the copy and do nothing. You cannot have two files with the same name in the same folder.
Without the prompt you WILL ovrwrite the exisitng file which is probably what you dont want.
Stuart

I am trying to copy a directory of files but I would only like to
copy files which do not exist in the destination directory.

Here is a VBScript to do it, this script will not overwrite existing files, All you have to do is change the two variable's strSourceDir and strDestinDir. Copy the script into a .vbs file and run it. Side note, *.* in the source will copy all files of any type from the source dir, if you want to only copy *.txt or whatever modifie accordingly, also the destination directory must end with a "\" so that the script knows that it is a folder. IF you want to overwrite existing files all you have to do is change the const overwriteexisting from False to True.
Option Explicit
Dim strSourceDir, strDestinDir, FSO
const OverwriteExisting = FalsestrSourceDir = "C:\test1\*.*" 'change this line
strDestinDir = "C:\test2\" 'change this lineon error resume next
set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile strSourceDir , strDestinDir , OverWriteExisting

There must be a simple command to do the exact opposite of
xcopy /u source\* dest\Since I can't find such a command, here is a batch script (use either this one or gtaion's VBScript):
for %%a in (source\*) do ( if not exist dest\%%~nxa ( copy %%a dest ) )

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |