Is very basic, currently it only list the duplicate files (of any extension) in the current directory.
Note: the hidden files are not considered.
If a duplicate file is found, the origin file is printed in yellow, and the duplicates in red.
If none duplicate file is found, a message in green says it.
example:
edit: updated version to 0.35 that have the most updated fixes.
dup.cmd
Code: Select all
@echo off
::dup
::list duplicate files by content in the current directory.
::a file is considered duplicated if have:
::the same crc32 checksum and file size
::version: 0.35 :
:: bugfixed problem with filenames with special characters.
:: bugfixed problem with short filenames in windows xp.
:: bugfixed problem using cmd /u.
:: bugfixed problem with filenames having exclamation character.
::author: cmontiers
setlocal enableextensions disabledelayedexpansion
call :color 70 "working ..."
for %%. in (.) do set "curr_drv=%%~d."
subst +: /d >nul & subst +: "." & +:
set "aecho=cmd /a /d /c echo"
for %%# in ("%temp%") do set "temp=%%~s#"
set "inffile=%temp%\dup.inf"
set "cnffile=%temp%\dup.cfg"
if exist "%inffile%" del "%inffile%"
if exist "%cnffile%" del "%cnffile%"
(
%aecho% .set destinationdir="%temp%"
%aecho% .set diskdirectorytemplate=""
%aecho% .set inffooter=""
%aecho% .set infheader=""
%aecho% .set infdisklineformat=""
%aecho% .set donotcopyfiles=on
%aecho% .set destinationdir=""
%aecho% .set rptfilename=nul
%aecho% .set checksumwidth=8
%aecho% .set cabinet=off
%aecho% .set compress=off
%aecho% .set generateinf=on
%aecho% .set infdiskheader=""
%aecho% .set inffileheader=""
%aecho% .set infcabinetheader=""
%aecho% .set inffilelineformat="*csum*:*size* *file*"
for %%# in (*) do if not "%inffile%"=="%%~s#" (
if not "%cnffile%"=="%%~s#" %aecho% "%%~s#"
)
) > "%cnffile%"
makecab /d "inffilename=%inffile%" /f "%cnffile%" >nul
set "dup=0"
set "last_hash="
set "last_origin_name="
for /f "tokens=1,*" %%a in ('sort "%inffile%"') do (
if not "%%~a"=="" (
for /f "tokens=*" %%n in ('dir /a /b "%%~b"') do (
setlocal enabledelayedexpansion
if not "%%~a"=="!last_hash!" (
endlocal
set "last_origin_name=%%~n"
) else (
if 0 equ !dup! call :del_characters 11
endlocal
set "dup=1"
if defined last_origin_name (
setlocal enabledelayedexpansion
call :color 0e "!last_origin_name!" \n
endlocal
set "last_origin_name="
)
set "fullname=%%~n"
setlocal enabledelayedexpansion
call :color ce "[*]" 00 " " 0c "!fullname!" \n
endlocal
)
set "last_hash=%%~a"
)
)
)
if 0 equ %dup% (
call :del_characters 11
call :color 0a "no duplicate files found" \n
)
del "%inffile%" "%cnffile%"
%curr_drv%
goto :eof
:del_characters
for /f %%# in (
'"prompt $h &for %%_ in (_) do rem"'
) do for /l %%_ in (1,1,%~1) do set /p "=%%# %%#" <nul
goto :eof
:color
:: v23c
:: arguments: hexcolor text [\n] ...
:: \n -> newline ... -> repeat
:: supported in windows xp, 7, 8.
:: this version works using cmd /u
:: in xp extended ascii characters are printed as dots.
:: for print quotes, use empty text.
setlocal enableextensions enabledelayedexpansion
subst `: "!temp!" >nul &`: &cd \
setlocal disabledelayedexpansion
echo(|(pause >nul &findstr "^" >`)
cmd /a /d /c set /p "=." >>` <nul
for /f %%# in (
'"prompt $h &for %%_ in (_) do rem"') do (
cmd /a /d /c set /p "=%%# %%#" <nul >`.1
copy /y `.1 /b + `.1 /b + `.1 /b `.3 /b >nul
copy /y `.1 /b + `.1 /b + `.3 /b `.5 /b >nul
copy /y `.1 /b + `.1 /b + `.5 /b `.7 /b >nul
)
:__color
set "text=%~2"
if not defined text (set text=^")
setlocal enabledelayedexpansion
for %%_ in ("&" "|" ">" "<"
) do set "text=!text:%%~_=^%%~_!"
set /p "lf=" <` &set "lf=!lf:~0,1!"
for %%# in ("!lf!") do for %%_ in (
\ / :) do set "text=!text:%%_=%%~#%%_%%~#!"
for /f delims^=^ eol^= %%# in ("!text!") do (
if #==#! endlocal
if \==%%# (findstr /a:%~1 . \` nul
type `.3) else if /==%%# (findstr /a:%~1 . /.\` nul
type `.5) else (cmd /a /d /c echo %%#\..\`>`.dat
findstr /f:`.dat /a:%~1 .
type `.7))
if "\n"=="%~3" (shift
echo()
shift
shift
if ""=="%~1" del ` `.1 `.3 `.5 `.7 `.dat &goto :eof
goto :__color