Computing.Net > Forums > Programming > How tp copy, not overwrite, and not prompt?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How tp copy, not overwrite, and not prompt?

Reply to Message Icon

Name: techphets
Date: August 24, 2009 at 17:46:22 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Hi,

How can I copy files, not overwrite existing
files, and not prompt?

I see how to do this with overwriting but not
without.



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: August 24, 2009 at 18:16:03 Pacific
Reply:

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


0

Response Number 2
Name: StuartS
Date: August 24, 2009 at 18:16:03 Pacific
Reply:

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


0

Response Number 3
Name: techphets
Date: August 24, 2009 at 19:09:11 Pacific
Reply:

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.


0

Response Number 4
Name: gtaion
Date: August 24, 2009 at 20:57:57 Pacific
Reply:

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 = False

strSourceDir = "C:\test1\*.*" 'change this line
strDestinDir = "C:\test2\" 'change this line

on error resume next
set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile strSourceDir , strDestinDir , OverWriteExisting


0

Response Number 5
Name: klint
Date: August 25, 2009 at 08:21:41 Pacific
Reply:

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
   )
)


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: How tp copy, not overwrite, and not prompt?

Copy Paste Files and Folder www.computing.net/answers/programming/copy-paste-files-and-folder/20150.html

batch folder copying www.computing.net/answers/programming/batch-folder-copying/16133.html

VBA - Insert Row(s), Copy 1 Cell www.computing.net/answers/programming/vba-insert-rows-copy-1-cell/16501.html