Batch Script: Delete Files from Folder not in another Folder
Question by Guest | 2023-06-26 at 22:45
I found this on the web but it does the opposite of what it says. It deletes files that match. Can anyone help?
I use the following to compare files within different folders and delete the ones from first folder which does not exists on second one.
echo off set "Folder1=C:\Documents and Settings\Administrator\My Documents\My Pictures" set "Folder2=C:\Documents and Settings\Administrator\My Documents\My eBooks" for /f "delims=" %%F in ('dir /b "%folder2%"') do ( if not exist "%folder1%\%%F" ( fc /b "%folder1%\%%F" "%folder2%\%%F" if "%errorlevel%" EQU "1" ( del "%folder1%\%%F" && echo Deleted "%%F" ) else ( del "%folder1%\%%F" && echo Deleted "%%F" pause Exit
Related Topics
Rename File to its Folder Name
Tutorial | 0 Comments
MySQL: Delete Data from Table - Difference between TRUNCATE, DELETE and DROP
Tutorial | 0 Comments
Windows Batch Script: Computer Shutdown
Tutorial | 2 Comments
Rewrite Text Files with a fixed Line Length
Tutorial | 0 Comments
Website Performance: Deliver JavaScript and CSS files compressed to reduce loading times
Tutorial | 0 Comments
Repair Text Files with mixed Line Breaks
Tutorial | 0 Comments
Convert many CSV Files to XLSX or ODS Spreadsheets
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
Are you sure this is the full script? There are some brackets missing.
And why are the two lines in the last if condition the same?
What if you change "if not exist" to "if exist"?
2023-06-27 at 03:20