7

I'm on Windows 7 Professional, and this is my scenario :

Folder "Asd" (C:\)              Folder "Asd" (D:\)
File 1                          File 1 
File 2                          File 3 
File 3                          File 4
File 4
File 5

I'd like to select the folder on C:\ (without selecting each single file, of course) and copy it over the same folder on D:. Usually, it will copy all files. But what I'm looking for is to copy only files (from C:) that are contained on folder d:.

So in my case I'd like to replace only File 1, File 3 and File 4. File 2 and File 5 must be ignored.

Is it possible?

Flyk
  • 1,539
  • 1
  • 21
  • 28
markzzz
  • 717
  • 3
  • 13
  • 22

5 Answers5

12

When you want to copy, robocopy always has the right switch to do it.
Here you want the /XL switch to exclude “lonely” files:

robocopy C:\ D:\ /S /XL

This will work with files or folders.

Benoit
  • 6,993
  • 4
  • 23
  • 31
6

Try using XCOPY command:-

Syntax:

xcopy sourceDirectory DestinationDirectory /U /Y

 /U           Copies only files that already exist in destination.
 /Y           Suppresses prompting to confirm you want to overwrite an
              existing destination file.

Example:

xcopy D:\Temp\test\*.* D:\Temp\test11 /U /Y

*.* - indicates all files in this directory

Here it overrides the files in destination folder "D:\Temp\test11" folder with the files from source

Siva Charan
  • 4,865
  • 2
  • 25
  • 29
1

A simple for-loop combined with a dir /b should work. Something like this:

FOR /F %X IN ('dir /b D:\Asd') DO copy "C:\Asd\%X" "D:\Asd\%X"

If you're using a batch file, replace %X with %%X (something to do with they way how Windows processes variables, it's different from the command line).

Oldskool
  • 664
  • 3
  • 13
  • OH! With GUI is it not possible? – markzzz Feb 06 '12 at 09:08
  • @Markzz, no I don't think so. Oldskool, shouldn't that be "FOR /F %X IN ('dir /b D:\Asd')..." ? – RJFalconer Feb 06 '12 at 09:13
  • @markzzz Ah, didn't realize it had to be a GUI solution. Windows doesn't have that kind of functionality by default, you'd probably have to look for a custom piece of software that does that if command-line is not an option. – Oldskool Feb 06 '12 at 09:14
  • @RJFalconer You are right! Updated the answer, thanks. – Oldskool Feb 06 '12 at 09:14
  • @markzzz I think that the tool [Total Commander](http://www.ghisler.com/index.htm) does have a [directory comparison function](http://www.ghisler.com/screenshots/en/08.html) that you could use for this. – Oldskool Feb 06 '12 at 09:20
  • @Oldskool - I would make a little change: `FOR /F %X IN ('dir /b D:\Asd') DO` **if exist "C:\Asd\%X"** `copy "C:\Asd\%X" "D:\Asd\%X"` to prevent trying to copy files that don't exist on C: but do exist on D: – Kevin Fegan Nov 28 '12 at 19:06
1

Check the Troubleshooting IT Issues blog for solution for Robocopy rooting files like PST

net use n: \\server\backup
echo %computername%
mkdir n:\%computername%
SET SourceDir= n:\%computername%
SET Log="n:\%computername%.log"
robocopy c:\ %SourceDir% *.doc* *.ppt* *.xls* *.pst* *.pdf /s /LOG:%Log%

The addition of * on either side of the office documents is to ensure that you copy all versions from Office-2k3 and above. I have also included the PST files.

slhck
  • 223,558
  • 70
  • 607
  • 592
yeshudas
  • 11
  • 1
0

To go alongside the robocopy and xcopy methods, here's the solution with JP Software's TCC/LE and copy:

copy /c c:\asd\ d:\asd\
JdeBP
  • 26,613
  • 1
  • 72
  • 103