Cmpr_Del.btm need help understanding UDF.....

#1
I am unsure and hence would like some assistance in writing a user-defined function, calling it too, please.

It's attached to this post....

Thank you for your assistance....
 

Attachments

samintz

Scott Mintz
May 20, 2008
1,313
11
Solon, OH, USA
#2
Charles, the code as you've written it is more like a subroutine than a FUNCTION. Subroutines are accessed by GOSUB.

Have you considered downloading the free tool WinMerge? It allows you to compare individual files as well as entire directory trees.

Here is my take on a solution for you:
Cmpr_del.btm:
Code:
setlocal
rem returns 1 if files are identical, 0 otherwise
function IsDuplicate=`%@if[%@crc32[%1]==%@crc32[%2],1,0]`
rem returns a relative path 
function relpath=`%@right[-%@len[%1],%2]`
rem convert relative input paths to full paths
set f1=%@full[%1]
set f2=%@full[%2]
rem iterate over all the files from the source tree
do f in /a:-d /d"%f1" /s *
  rem files are names only in a DO loop. Convert to full path
  set sf=%_cwd\%f
  rem convert the full path into a relative path and prepend the dest
  set df=%[f2]%@relpath[%f1,%sf] 
  rem test for duplicate
  iff exist "%df" .and. %@IsDuplicate["%sf","%df"]==1 then
        echo %f is duplicated in %df
  endiff
enddo
 
#3
Or just modify it to use correct subroutine syntax ... something like this (untested, and no doubt needs work)
Code:
global /i /q /h for %fn in (*) if %@exec[gosub samefile%fn %1 %2] == 1 echo %1\%fn is duplicated in %2
QUIT

:samefile [fn root1 root2]
  set name1=%root1\%fn
  set name2=%root2\%fn
  iff %@filedate[%name1] eq %@filedate[%name2] .and. %@filetime[%name1] eq %@filetime[%name2] .and. %@filesize[%name1,b] eq %@filesize[%name2,b] .and.%@crc32[%name1] eq %@crc32[%name2] then
    return 1
  endiff
return 0