compare directory contents

D

djc

Is there a simple command to compare directory contents? I'm thinking
something that you supply 2 directory names to as parameters and it spits
out a list of files that ARE in one directory but not in the other?

I know I can acheive similar results combining commands like getting dir
output from both directories in question redirected to 2 different text
files that I could then use fc or comp on. I just wanted to know if there
was an easier way.

anyone?
 
P

Phil Robyn [MVP]

djc said:
Is there a simple command to compare directory contents? I'm thinking
something that you supply 2 directory names to as parameters and it spits
out a list of files that ARE in one directory but not in the other?

I know I can acheive similar results combining commands like getting dir
output from both directories in question redirected to 2 different text
files that I could then use fc or comp on. I just wanted to know if there
was an easier way.

anyone?

http://sourceforge.net/projects/winmerge/
 
M

Matthias Tacke

djc said:
Is there a simple command to compare directory contents? I'm thinking
something that you supply 2 directory names to as parameters and it spits
out a list of files that ARE in one directory but not in the other?

I know I can acheive similar results combining commands like getting dir
output from both directories in question redirected to 2 different text
files that I could then use fc or comp on. I just wanted to know if there
was an easier way.

anyone?
That is what batches are for, easing tedious tasks :)

A batch only solution for w2k/xp (nt also if %%~aA is removed)
It simply compares file names not dates, nor identity.
The batch may be enhanced to omit headers when nothing follows.

::DirComp.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
if "%~2"=="" goto :Usage
if not exist "%~1" goto :Usage
if not exist "%~2" goto :Usage
for /f "tokens=*" %%A in ("%~1") do set "FldSrc=%%~fA"&set "FldSrcAtr=%%~aA"
for /f "tokens=*" %%A in ("%~2") do set "FldDst=%%~fA"&set "FldDstAtr=%%~aA"
if "dd" NEQ "%FldSrcAtr:~,1%%FldDstAtr:~,1%" echo wrong Attr &goto :Usage
::Checks done, get Folders
pushd "%FldSrc%"
dir /B /A-D >"%Temp%\FldSrc.txt"
cd /d "%FldDst%"
dir /B /A-D >"%Temp%\FldDst.txt"
echo/======== Files in Src not in Dest ========
findstr /V /G:"%Temp%\FldDst.txt" <"%Temp%\FldSrc.txt"
echo/======== Files in Dest not in Src ========
findstr /V /G:"%Temp%\FldSrc.txt" <"%Temp%\FldDst.txt"
echo/========
popd
for %%A in (Src Dst) do del "%Temp%\Fld%%A.txt"
goto :eof
:Usage
echo/ Usage: %~nx0 SourceFolder DestFolder
echo/ Lists Files in Source and not in Dest and vice versa.
::DirComp.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::::

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top