Very simply, for each file in a folder (C:\Pers\test1), I would like to check to see if the file exists in another folder (C:\Pers\test2). If the file exists in test2, then delete it from test1.
Here's my latest attempt after poking around here and on other forums. It does not seem to be doing anything.
Code: Select all
@Echo off
SET LOGFILE=C:\Pers\deletedfiles.log
echo %date% %time% >> %LOGFILE%
call :Tolog >> %LOGFILE%
exit /b 0
:Tolog
setlocal
echo Deleting the following files...
SET orgfolder = C:\Pers\test1
SET newfolder = C:\Pers\test2
cd /d "%orgfolder%"
FOR %%a in (*.*) DO(
IF EXIST "%newfolder%\%%~nxa" (
del %orgfolder%\%%~nxa
echo %%~nxa
) else (
echo MISSING %%~nxa
)
)
Thanks in advance for your assistance.