Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 2 folders with files. These files are the product of some build process. The first folder is the outputs of previous build while the latter is the output of the current build.

I would like to somehow diff these 2 folders from the command line/build script and copy only files that were added or files that are new into some other folder.

For example:

**FOLDER1** (new build)
b.txt (modified)

**FOLDER2** (prev build)

Based on this, the copy operation i am interested in, will copy only b.txt and d.txt into some other folder (not into folder2).

Basically, i am only after the "deltas" and i would like to store these some place.

Is this possible using standard command line tools that come with Windows? (suppose Windows 7/Server 2008 or higher)

share|improve this question
This is a long-roundabout way to do it, but maybe just xcopy with the date flag set. Though, if b in F1 is newer than newfolder, it will copy and if b in F2 is newer than in F1 - it will copy too. So with large filesizes, it degrades quickly (hence the non-answer). It may be worth researching and doing some logic for a .bat with xcopy /c/h/e/v/y/d – nerdwaller Dec 17 '12 at 15:22
i am not after copying the deltas to FOLDER2. I want to create a folder containing ONLY THE DELTAS (copy them to FOLDER3 somehow). – liortal Dec 17 '12 at 15:41
That's what I suggested... You would first check Folder1 vs Folder3 then Folder2 vs Folder 3. You would always have the most recent revision in Folder3 of all files. However, as I said, with large file sizes this is extremely inefficient - so I did not post it as an answer. – nerdwaller Dec 17 '12 at 15:45
Folder3 is always initialized as empty. I want to compare F1 and F2, and copy newest stuff to F3. F3 at the end would contain only the latest stuff. – liortal Dec 17 '12 at 15:55
If you compare F1 to F3 and F2 to F3, you essentially do that, since if F3 is empty you get all of F1 then you could compare F2 to F3 (i.e. F1) and you'd have the latest. Again, very inefficient - so it's not an answer... – nerdwaller Dec 17 '12 at 16:00

Use XCOPY with /D and /L options, "copying" from folder 1 to folder 2.

The /D option restricts the copy to only new or modified files.

The /L option causes the command to list the files that would be copied, but prevents any copies from actually being made.

Then use FOR /F to process those results and actually copy the files to folder 3.

for /f "eol=: delims=" %F in ('xcopy /dl "folder1\*" "folder2"') do @copy "%%F" "f3" >nul

If put in a batch file, then all % must be doubled as %%.

The XCOPY also prints out a summary of how many files are (would be) affected. The above will attempt to copy a file with the summary count "name", and of course fail. The redirection of output to nul prevents the error message from displaying. I tested on Windows 7 and was surprised the error message was on stdout and not stderr. If the error message on other versions is appearing on stderr, then the command should also get 2>nul to prevent the error message.

share|improve this answer
Thanks, i guess i will go down with this approach or similar. I think XCOPY will still copy the files in case they have the same date though (f1 and f2 contain exactly the same files and dates -- all files will still be copied). – liortal Dec 18 '12 at 5:53
@liortal - Not quite. I believe it does exactly what you want. The file is copied only if either the file exists in f1 and not f2, or if the last modified timestamp in f1 is newer than in f2. If the timestamp is the same or older in f1, then the file is not copied. – dbenham Dec 18 '12 at 12:11
try to setup 2 folders with exact same files and copy using xcopy /d. From what i've seen it copies the files in this case. – liortal Dec 18 '12 at 13:13
I did that test case and it worked. I created F1 folder with files, and then copied those files to F2. Then I modified one file in F1. COPY /D only copies the modified file. – dbenham Dec 18 '12 at 14:40
What's the reasoning for not just using xcopy directly? If it can list the necessary files, can't it also copy the necessary files? – trlkly May 13 '14 at 20:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.