Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

CmprTree Dir1 Dir2

Apr
1,822
17
I'm wondering if someone has a CmprTree BTM I can use please? It would:

cmprtree.btm "c:\program files\" "c:\windows.old\program files\"

for each file in c:\program files\subdir1\filename.ext, and if c:\windows.old\program files\subdir1\filename.ext exists and is the same - would delete the file under c:\windows.old\......

for each file in c:\windows.old\program files\subdir1\filename.ext, and if c:\program files\subdir1\filename.ext exists and is the same - would delete the file under c:\program files\......
 
This could potentially work. But it is untested.
Code:
set sd=c:\program files
set od=c:\windows.old\program files\
do d in /d"%sd" /s /a:-d * 
  set rp=%@right[-%@len[%sd],%cd]
  iff exist %[od]%rp\%d then
    if %@sha1[%[od]%rp\%d] == %@sha1[%[cd]\%d] del %[cd]\%d
  endiff
enddo
 
You don't really want to delete the ones in c:\program files ... do you?

This basically works. There's no deleting and it needs thorough testing and probably a lot of polishing. I was using Windows's FC.EXE to do the comparing (sending the output to NUL and checking %?). Thanks Scott for the @SHA1 idea (though I doubt it's any faster).

Code:
setlocal

set dir1=%@upper[%1]
set dir2=%@upper[%2]

do dir in /d"%dir1" /s /a:+d * ( gosub comparedirs )
quit

:comparedirs
do file in /a:-d *
    set file1=%@upper[%@full[%file]]
    set file2=%@replace[%dir1,%dir2,%file1]
    echo file1 = %file1
    echo file2 = %file2
    iff exist %file2 then
        echo %file2 exists and is %@if[%@sha1[%file1] == %@sha1[%file2],the same as,different from] %file1
    endiff

        
enddo

Here's a snippet of its output.

Code:
dircmp.btm v:\anon1\ v:\anon2\

file1 = V:\ANON1\SWAPARGS.ZIP
file2 = V:\ANON2\SWAPARGS.ZIP
V:\ANON2\SWAPARGS.ZIP exists and is the same as V:\ANON1\SWAPARGS.ZIP
file1 = V:\ANON1\TEST
file2 = V:\ANON2\TEST
V:\ANON2\TEST exists and is different from V:\ANON1\TEST
 
Wouldn't @compare[] be better then any of the sha* functions?
 
@vefatica doesn't @compare do a byte by byte comparison, so more accurate then what the sha* routines do?

Code:
setlocal

set dir1=%@UNQUOTES[%1]
set dir2=%@UNQUOTES[%2]

echo %dir1
echo %dir2
pause

if "%@right[1,%dir1]" NE "\" set dir1=%dir1\
if "%@right[1,%dir2]" NE "\" set dir2=%dir2\

echo %dir1
echo %dir2
pause

do dir in /d"%dir1" /s /a:+d * ( gosub comparedirs )
quit

:comparedirs

pause %_CWD, %dir1

do file in /a:-d *

    pause %file

    set file1=%@full[%file]
    set file2=%@replace[%dir1,%dir2,%file1]
    rem COMMENT
      echo file1 = %file1
      echo file2 = %file2
    rem ENDCOMMENT
    iff exist %file2 then
        iff %@compare[%file1,%file2] == 1 then
           echo files are the same
           echo del %file2>>! %userprofile%\OneDrive\Desktop\del_me.btm
        else
           echo files are different
        endiff
    else
      echo %file2 does not exist
    endiff

enddo

Trying this out, somehow file1 and file2 are set to the same exact file...... - any ideas what is wrong?
 
@vefatica doesn't @compare do a byte by byte comparison, so more accurate then what the sha* routines do?
I suppose it has to. But @SHA1 also does a calculation.
Trying this out, somehow file1 and file2 are set to the same exact file...... - any ideas what is wrong?
Maybe it's the problem I ran into at first. @REPLACE is case sensitive (and if the case isn't right it won't replace anything). That's why I put @UPPER in there.
 
Note: @SHA1 has to go all the way through two files, doing a bit of math with each byte, @COMPARE, goes all the way through only once, at most ... if a pair of bytes don't match it can stop.
 
Note: @SHA1 has to go all the way through two files, doing a bit of math with each byte, @COMPARE, goes all the way through only once, at most ... if a pair of bytes don't match it can stop.

I don't have access to Rex's source. But a cleverly-written @COMPARE may be able to decide two files are identical, or are different, without reading from either one.
 
I don't have access to Rex's source. But a cleverly-written @COMPARE may be able to decide two files are identical, or are different, without reading from either one.
Umm! Different sizes means different files. But if the sizes are the same, how can you tell the difference without reading?
 
Code:
CmprTree.btm "c:\Program Files\" "c:\Windows.old\Program Files\"

[C:\]c:\TCMD\BTMs\CmprTree.btm "c:\Program Files\" "c:\Windows.old\Program Files\"
c:\Program Files\
c:\Windows.old\Program Files\
Press any key when ready...
c:\Program Files\
c:\Windows.old\Program Files\
Press any key when ready...
C:\Program Files, c:\Program Files\
desktop.ini
file1 = C:\Program Files\desktop.ini
file2 = C:\Program Files\desktop.ini
TCC: (Sys) C:\TCMD\BTMs\CmprTree.btm [35]  The system cannot find the file specified.
 ""
files are different
C:\Program Files, c:\Program Files\
 
Umm! Different sizes means different files. But if the sizes are the same, how can you tell the difference without reading?

Usually you can't. But if they are on the same volume and have the same inode, then you're looking at two names for the same thing.
 
I don't know if it's the only problem, but %@compare[%file1,%file2] needs "%file1" and "%file2".

And @REPLACE is case sensitive.
 
Did you get it working @Charles G? I took a different approach ... using GLOBAL ... because DO /S didn't get files in the top directory. Code and results are below but first a question. Can I use /a:... to get ALL files but NO directories?

Code:
setlocal

set dir1=%@upper[%@unquotes[%1]]
set dir2=%@upper[%@unquotes[%2]]
echo dir1 = %dir1
echo dir2 = %dir2

cdd %dir1

global /h /i /q (if %@files[*,-d] GT 0 gosub comparedirs)

quit

:comparedirs
do file in /a: *
    if isdir %file return
    set file1=%@upper[%_cwd\%file]
    set file2=%@replace[%dir1,%dir2,%file1]
    echo file1 = %file1
    echo file2 = %file2
    iff exist %file2 then
        echo %file2 exists and is %@if[%@compare["%file1","%file2"] == 1,the same as,different from] %file1
    else
        echo %file2 does not exist
    endiff
enddo
return

Code:
V:\anon 1\
├──folder
│  ├  test
│  ├  vef
│  └  version.txt
└──folder2
   └  desktop.ini

v:\> tree /f /a: /h "anon 2"\

V:\anon 2\
└──folder
   ├  RegTweaks.btm
   ├  test
   └  vef

v:\> dircmp2.btm "v:\anon 1\" "v:\anon 2\"
dir1 = V:\ANON 1\
dir2 = V:\ANON 2\
file1 = V:\ANON 1\FOLDER\TEST
file2 = V:\ANON 2\FOLDER\TEST
V:\ANON 2\FOLDER\TEST exists and is different from V:\ANON 1\FOLDER\TEST
file1 = V:\ANON 1\FOLDER\VEF
file2 = V:\ANON 2\FOLDER\VEF
V:\ANON 2\FOLDER\VEF exists and is the same as V:\ANON 1\FOLDER\VEF
file1 = V:\ANON 1\FOLDER\VERSION.TXT
file2 = V:\ANON 2\FOLDER\VERSION.TXT
V:\ANON 2\FOLDER\VERSION.TXT does not exist
file1 = V:\ANON 1\FOLDER2\DESKTOP.INI
file2 = V:\ANON 2\FOLDER2\DESKTOP.INI
V:\ANON 2\FOLDER2\DESKTOP.INI does not exist
 
@vefatica - any way to get it working w/o having to upper[] the 2 passed params?
Not if you use @REPLACE (which is case sensitive). You could probably piece together file2 by getting the @LEN of dir1 and making file2 contain dir2 followed by file1 with the leftmost length_of_dir1 characters removed [Scott was doing something like that]. This seems to work. What's the matter with @UPPER?

Note that I also quoted %file2 in the IF EXIST line (I wonder why it worked without that(?).

Code:
v:\> type dircmp2.btm
setlocal

set dir1=%@unquotes[%1]
set dir2=%@unquotes[%2]
echo dir1 = %dir1
echo dir2 = %dir2

cdd %dir1

global /h /i /q (if %@files[*,-d] GT 0 gosub comparedirs)

quit

:comparedirs
do file in /a: *
    if isdir %file return
    set file1=%_cwd\%file
    set file2=%[dir2]%@right[-%@len[%dir1],%file1]
    echo file1 = %file1
    echo file2 = %file2
    iff exist "%file2" then
        echo %file2 exists and is %@if[%@compare["%file1","%file2"] == 1,the same as,different from] %file1
    else
        echo %file2 does not exist
    endiff
enddo
return

v:\> dircmp2.btm "v:\anon 1\" "v:\anon 2\"
dir1 = v:\anon 1\
dir2 = v:\anon 2\
file1 = V:\anon 1\folder\test
file2 = v:\anon 2\folder\test
v:\anon 2\folder\test exists and is different from V:\anon 1\folder\test
file1 = V:\anon 1\folder\vef
file2 = v:\anon 2\folder\vef
v:\anon 2\folder\vef exists and is the same as V:\anon 1\folder\vef
file1 = V:\anon 1\folder\version.txt
file2 = v:\anon 2\folder\version.txt
v:\anon 2\folder\version.txt does not exist
file1 = V:\anon 1\folder2\desktop.ini
file2 = v:\anon 2\folder2\desktop.ini
v:\anon 2\folder2\desktop.ini does not exist
 
[omit] What's the matter with @UPPER? [omit]
[/code]

Because I do not have a file called
"C:\WINDOWS.OLD\PROGRAM FILES\WINDOWS MULTIMEDIA PLATFORM\SQMAPI.DLL"

but instead have one called

"C:\Windows.old\Program Files\Windows Multimedia Platform\sqmapi.dll"

to be 100% correct.....
 
Works great and very simple. however - what if it's called:

dircmp2.btm "v:\anon 1" "v:\anon 2\"

or

dircmp2.btm "v:\anon 1\" "v:\anon 2"
 
@vefatica I also have files called "Canvas Blue & Tan.jpg" - the "&" is causing errors. Isn't it

SETDOS /X-5

and I changed some lines to:

Code:
        iff %@compare["%file1","%file2"] == 1 then
          echo del "%file2" >>! "%userprofile%\OneDrive\Desktop\del_me.btm"
        endiff
 
Here's a nifty way to insure the trailing \ and unquote.

Code:
setlocal

cdd %2
set dir2=%_cwds
cdd %1
set dir1=%_cwds
echo dir1 = %dir1
echo dir2 = %dir2

global /h /i /q (if %@files[*,-d] GT 0 gosub comparedirs)
...
 
@vefatica Any ideas what is causing the

TCC: C:\TCMD\BTMs\dircmp2.btm [20] Missing GOSUB

???

Code:
[C:\]c:\TCMD\BTMs\dircmp2.btm "c:\Program Files\" "c:\Windows.old\Program Files\"
dir1 = C:\Program Files\
dir2 = C:\Windows.old\Program Files\
TCC: C:\TCMD\BTMs\dircmp2.btm [20]  Missing GOSUB
file1 = C:\Program Files\7-Zip
file2 = C:\Windows.old\Program Files\7-Zip
C:\Windows.old\Program Files\7-Zip does not exist
Press any key when ready...
===========================================================
TCC: C:\TCMD\BTMs\dircmp2.btm [20]  Missing GOSUB
file1 = C:\Program Files\Advanced Renamer
file2 = C:\Windows.old\Program Files\Advanced Renamer
C:\Windows.old\Program Files\Advanced Renamer does not exist
Press any key when ready...
===========================================================
TCC: C:\TCMD\BTMs\dircmp2.btm [20]  Missing GOSUB
file1 = C:\Program Files\CCleaner
file2 = C:\Windows.old\Program Files\CCleaner
C:\Windows.old\Program Files\CCleaner does not exist
Press any key when ready...
===========================================================
TCC: C:\TCMD\BTMs\dircmp2.btm [20]  Missing GOSUB
file1 = C:\Program Files\Common Files
file2 = C:\Windows.old\Program Files\Common Files
TCC: (Sys) C:\TCMD\BTMs\dircmp2.btm [26]  Access is denied.
 ""
Press any key when ready...
===========================================================
file1 = C:\Program Files\desktop.ini
file2 = C:\Windows.old\Program Files\desktop.ini
Press any key when ready...
===========================================================
TCC: C:\TCMD\BTMs\dircmp2.btm [20]  Missing GOSUB
file1 = C:\Program Files\Family Tree Maker 2019
file2 = C:\Windows.old\Program Files\Family Tree Maker 2019
C:\Windows.old\Program Files\Family Tree Maker 2019 does not exist
Press any key when ready...
===========================================================
TCC: C:\TCMD\BTMs\dircmp2.btm [20]  Missing GOSUB
file1 = C:\Program Files\Hewlett-Packard
file2 = C:\Windows.old\Program Files\Hewlett-Packard
C:\Windows.old\Program Files\Hewlett-Packard does not exist
Press any key when ready...
===========================================================
TCC: C:\TCMD\BTMs\dircmp2.btm [20]  Missing GOSUB
file1 = C:\Program Files\hp
file2 = C:\Windows.old\Program Files\hp
C:\Windows.old\Program Files\hp does not exist
Press any key when ready...
===========================================================
TCC: C:\TCMD\BTMs\dircmp2.btm [20]  Missing GOSUB
file1 = C:\Program Files\HPPrintScanDoctor
file2 = C:\Windows.old\Program Files\HPPrintScanDoctor
C:\Windows.old\Program Files\HPPrintScanDoctor does not exist
Press any key when ready...
===========================================================
TCC: C:\TCMD\BTMs\dircmp2.btm [20]  Missing GOSUB
file1 = C:\Program Files\Internet Explorer
file2 = C:\Windows.old\Program Files\Internet Explorer
TCC: (Sys) C:\TCMD\BTMs\dircmp2.btm [26]  Access is denied.
 ""
Press any key when ready...
===========================================================
TCC: C:\TCMD\BTMs\dircmp2.btm [20]  Missing GOSUB
file1 = C:\Program Files\JPSoft
file2 = C:\Windows.old\Program Files\JPSoft
C:\Windows.old\Program Files\JPSoft does not exist
Press any key when ready...^C
 
What's the BTM look like?
Code:
setlocal

  setdos /x-5

  cdd %2
  set dir2=%_cwds
  cdd %1
  set dir1=%_cwds
  echo dir1 = %dir1
  echo dir2 = %dir2

  global /h /i /q (if %@files[*,-d] GT 0 gosub comparedirs)

endlocal

quit

:comparedirs
do file in /a: *
    if isdir %file return
    set file1=%_cwd\%file
    set file2=%[dir2]%@right[-%@len[%dir1],%file1]
    echo file1 = %file1
    echo file2 = %file2
    iff exist "%file2" then
        iff %@compare["%file1","%file2"] == 1 then
      echo del "%file2" >>! "%userprofile%\OneDrive\Desktop\del_me.btm"
        endiff
    else
    echo %file2 does not exist
    endiff
  pause
  echo ===========================================================
enddo
return
 
Hmmm! It didn't bite me, but according to the help

You cannot execute a RETURN from inside a DO loop.

So change "if isdir %file return" to "if isdir %file leave".
 
Some files are not being deleted. Even with
Code:
del /a: /f "filename"
- I guess they are locked. I even did
Code:
ATTRIB "filename"
and they had <A> - so I know it's not the file attribuites. Any thoughts?
 
Where are the files you're trying to delete? Do you get error messages? If a file is locked, FILELOCK might tell you the process that has it open.
 
Back
Top
[FOX] Ultimate Translator
Translate