Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy files easily

Status
Not open for further replies.

christhedonstar

Programmer
Apr 9, 2007
215
GB
Hi,

I have lots of data in a folder and I want to copy it to another folder (which already has some of the data) I don't want to have to wait for it to copy and overrite all files. I only want to overrite files which don't already exist in the 2nd file. I want to start the copy process and not have to be prompted for some input e.g. directory already exists do you want to overwrite. There are deep folder structures.

How do I do this?

Thanks,

Chris
 
I looked at the robocopy gui and there wasn't an obvious way to set it to do this.
 
Hi,
Use Window's own XCOPY command - withg options you can tell it what to do:

Windows_help said:
XcopyCopies files and directories, including subdirectories.

Syntax
xcopy Source [Destination] [/w] [/p] [/c] [/v] [/q] [/f] [/l] [/g] [/d[:mm-dd-yyyy]] [/u] [/i] [/s [/e]] [/t] [/k] [/r] [/h] [{/a|/m}] [/n] [/o] [/x] [/exclude:file1[+[file2]][+[file3]] [{/y|/-y}] [/z]

Parameters
Source
Required. Specifies the location and names of the files you want to copy. This parameter must include either a drive or a path.
Destination
Specifies the destination of the files you want to copy. This parameter can include a drive letter and colon, a directory name, a file name, or a combination of these.
/w
Displays the following message and waits for your response before starting to copy files:
Press any key to begin copying file(s)

/p
Prompts you to confirm whether you want to create each destination file.
/c
Ignores errors.
/v
Verifies each file as it is written to the destination file to make sure that the destination files are identical to the source files.
/q
Suppresses the display of xcopy messages.
/f
Displays source and destination file names while copying.
/l
Displays a list of files that are to be copied.
/g
Creates decrypted destination files.
/d[:mm-dd-yyyy]
Copies source files changed on or after the specified date only. If you do not include a mm-dd-yyyy value, xcopy copies all Source files that are newer than existing Destination files. This command-line option allows you to update files that have changed.
/u
Copies files from Source that exist on Destination only.
/i
If Source is a directory or contains wildcards and Destination does not exist, xcopy assumes destination specifies a directory name and creates a new directory. Then, xcopy copies all specified files into the new directory. By default, xcopy prompts you to specify whether Destination is a file or a directory.
/s
Copies directories and subdirectories, unless they are empty. If you omit /s, xcopy works within a single directory.
/e
Copies all subdirectories, even if they are empty. Use /e with the /s and /t command-line options.
/t
Copies the subdirectory structure (that is, the tree) only, not files. To copy empty directories, you must include the /e command-line option.
/k
Copies files and retains the read-only attribute on destination files if present on the source files. By default, xcopy removes the read-only attribute.
/r
Copies read-only files.
/h
Copies files with hidden and system file attributes. By default, xcopy does not copy hidden or system files.
/a
Copies only source files that have their archive file attributes set. /a does not modify the archive file attribute of the source file. For information about how to set the archive file attribute by using attrib, see Related Topics.
/m
Copies source files that have their archive file attributes set. Unlike /a, /m turns off archive file attributes in the files that are specified in the source. For information about how to set the archive file attribute by using attrib, see Related Topics.
/n
Creates copies by using the NTFS short file or directory names. /n is required when you copy files or directories from an NTFS volume to a FAT volume or when the FAT file system naming convention (that is, 8.3 characters) is required on the destination file system. The destination file system can be FAT or NTFS.
/o
Copies file ownership and discretionary access control list (DACL) information.
/x
Copies file audit settings and system access control list (SACL) information (implies /o).
/exclude:filename1[+[filename2]][+[filename3]]
Specifies a list of files containing strings.
/y
Suppresses prompting to confirm that you want to overwrite an existing destination file.
/-y
Prompts to confirm that you want to overwrite an existing destination file.
/z
Copies over a network in restartable mode.
/?
Displays help at the command prompt.




[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Which one is the option to not overwrite existing files but to copy all news ones including all subdirectories?
 
If I understand the original post correctly, you are effectively trying to merge two folders. Is that right?

You can do this with two xcopy commands, avoiding prompting. The first simply copies the 1st folder to a new folder and the second copies the 2nd folder over the first, replacing any files of the same name with the version in the 2nd folder.

Alternatively, there are some file merge tools on the Internet you can look at. Some of the them are freeware.
 
I Think your best option is a bat file.

Since xcopy can't overwrite read only files, you can change all files in the destination directory to read only, and then perform the copy with the /c switch so errors are ignored.

The list of copied files will show Access denied for files that could not be overwritten, but the rest of the files should copy.

Something like this:
Code:
@ECHO OFF
SET srcdir=%1
SET dstdir=%2
cd %dstdir%
attrib *.* +R
cd..
xcopy /y/c %srcdir% %dstdir%
cd %dstdir%
attrib *.* -R
cd..


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Robocopy command from the website I gave seemed to do the trick. Will properly check the results later...
 
Sorry to ask this silly question as I am new member of Tek-Tips would u be able to tell me how to start a new thread.
 
Go to main thread list, and scroll all the way down. The new thread box is at the bottom.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
In the main thread list there is also a "Start New Thread" link just before the first thread.

Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
That robocopy command to do it is no longer on that site I posted. Does anyone have the command?
 
Found it. Blog has changed to wordpress. I'm pasting it out here for future reference.


Merge directory trees using ROBOCOPY
Published 12 March 2007 Tech Leave a Comment

The "Robust File Copy for Windows" is more useful than XCOPY, with fewer side effects. Useful for merging directory trees (union), e.g. photo backups.

robocopy "F:\My Pictures" ".\home\photo" /E /XN /XF Thumbs.db

* /E Copy recursively, including empty directories
* /XN Exclude copy of newer files (if you don't trust/care about timestamps)
* /XF Thumbs.db Exclude files named Thumbs.db, produced by Windows
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top