@echo off
echo prune the O:\dl directory of files no longer in G:\dl directory tree

set source=G:\dl
set dest=O:\dl

rem delete files in dest that no longer exist on source

O:
cdd "%dest"
rem operate on each dir/file in dest in nested loop over each dir/fil.
rem Delete any file in dest that no longer exists in source
rem Use @replace to modify dest sub dir to equivalent sourcedir
rem Note the explicit cd to set to the found destdir directory. 4NT does not do that for you.
for /a:d /h /r %destdir in (*.*) do ( set sourcedir=%@replace[%dest,%source,%destdir ] & cd %destdir & for /a:-d %destfile in (*.*) do if not ISFILE "%sourcedir/%destfile" del "%destfile" )

rem -30-