Skip to content

Instantly share code, notes, and snippets.

@jpluimers
Created August 16, 2013 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpluimers/6248572 to your computer and use it in GitHub Desktop.
Save jpluimers/6248572 to your computer and use it in GitHub Desktop.
Up until Delphi 7, .ddp files were used to store the Diagram Portfolios. Often these files were empty like `Empty.ddp`, so this batch file helps to clean up those. https://bitbucket.org/jeroenp/besharp.net/commits/b07d3474006a0035a8ffac4d52ced5b1532a4d76#chg-Scripts/Delphi/delete-empty-DDP-files.bat
@echo off
if #%1#==## goto :help
setlocal
call :main %*
endlocal
goto :eof
:help
echo Syntax: %0 Project-Root-Path [Empty.ddp]
echo This will delete all empty DDP files, with the default second paramameter being "%~dp0Empty.ddp"
goto :eof
:main
set emptyDDP=%2
if #%2#==## set emptyDDP=%~dp0Empty.ddp
echo emptyDDP=%emptyDDP%
set root=%1
::echo root=%root%
::Does string have a trailing slash? if so remove it
if %root:~-1%==\ SET root=%root:~0,-1%
::echo root=%root%
for /R %root% %%f in (*.ddp) do call :compare "%%f"
goto :eof
:compare
::echo %1
:: do not compare the predefined empty one itself, otherwise it gets deleted
if /I %1=="%emptyDDP%" goto :eof
::echo before %ERRORLEVEL%
FC %1 "%emptyDDP%" > nul
::echo after %ERRORLEVEL%
if ERRORLEVEL 1 goto :keep
if ERRORLEVEL 0 goto :delete
echo ### Wrong ERRORLEVEL
goto :eof
:keep
echo keep %1
goto :eof
:delete
del %1
goto :eof
:eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment