C:\_G\WWW\~ELISANET\INFO\tscmd122.html
<http://www.elisanet.fi/tsalmi/info/tscmd122.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Sun 4-Nov-2018 17:12:56

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



122} How to list files present in folder A but not in folder B?

Q: I have a folder (Folder A) that has 11,156 files in it. I have a second folder (Folder B) that has 11,121 files in it. I want to generate a list of the files that exist in Folder A but not in B. How can I do this?

If you have the UNIX port egrep.exe then it is fairly simple:
  @echo off & setlocal enableextensions
  set folder1_=WhateverA
  set folder2_=WhateverB
  dir /b "%folder1_%">"%temp%\fold1.dir"
  dir /b "%folder2_%">"%temp%\fold2.dir"
  ::
  egrep -v -f "%temp%\fold2.dir" "%temp%\fold1.dir"
  ::
  for %%f in ("%temp%\fold*.dir") do if exist %%f del %%f
  endlocal & goto :EOF

The output might be something like
  C:\_D\TEST>cmdfaq
  BATFAQ.BAS
  BATFAQ.BAT
  BATFAQ2.BAT
  BATFAQ3.BAT
  CMDFAQ2.CMD
With the natural exception of the first and the last line the above solution is also MS-DOS+Win../95/98/Me compliant.

The task can also be solved with pure script, as below. The solution below has been expanded to include both the NOT and AND cases.
  @echo off & setlocal enableextensions enabledelayedexpansion
  set folder1_=C:\_D\TEST
  set folder2_=C:\_L\TODAY
  ::
  echo.
  echo Files that exist in %folder1_%
  echo but not in %folder2_%
  echo.
  for %%f in ("%folder1_%\*.*") do (
    if not exist "%folder2_%\%%~nxf" (
    set filename_=%%~dpnxf
    set filedate_=%%~tf
    set filesize_= %%~zf
    set filesize_=!filesize_:~-10!
    echo !filedate_! !filesize_! !filename_!))
  ::
  echo.
  echo Files that exist in %folder1_%
  echo AND in %folder2_%
  echo.
  for %%f in ("%folder1_%\*.*") do (
    if exist "%folder2_%\%%~nxf" (
      set filename_=%%~dpnxf
      set filedate_=%%~tf
      set filesize_= %%~zf
      set filesize_=!filesize_:~-10!
      echo !filedate_! !filesize_! !filename_!
      ::
      set filename2_=%folder2_%\%%~nxf
      for %%g in ("!filename2_!") do (
        set filename_=%%~dpnxg
        set filedate_=%%~tg
        set filesize_= %%~zg
        set filesize_=!filesize_:~-10!
        echo !filedate_! !filesize_! !filename_!)
      echo.
      )
    )
  ::
  endlocal & goto :EOF

The output might be something like
  C:\_D\TEST>cmdfaq

  Files that exist in C:\_D\TEST
  but not in C:\_L\TODAY

  19.02.2005 12:52         50 C:\_D\TEST\BATFAQ.BAS
  21.04.2005 00:29        824 C:\_D\TEST\BATFAQ.BAT
  17.04.2005 11:52      21928 C:\_D\TEST\BATFAQ2.BAT
  03.12.2002 07:58         90 C:\_D\TEST\BATFAQ3.BAT
  14.10.2005 17:40      12001 C:\_D\TEST\CMDFAQ2.CMD

  Files that exist in C:\_D\TEST
  AND in C:\_L\TODAY

  29.10.2005 06:58       1255 C:\_D\TEST\CMDFAQ.CMD
  28.10.2005 22:16        317 C:\_L\TODAY\CMDFAQ.CMD

Also see COMPFOLD.CMD

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd122.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd122
http://www.elisanet.fi/tsalmi/info/tscmd122.html
file:///c:/_g/www/~elisanet/info/tscmd122.html