Just wanted to ask for help in batch file. I need to have a text file where the file names of excluded files would be stored in the deletion of files with 6 months above date.
Inside list.txt are trial.csv, trial2.csv which are older than 6 months but should be excluded in the deletion since it is in my list.
I have this code but can't seem to make it work. Please help
@echo off
set exclude_file=C:\Users\Desktop\Test\list.txt
set directory=C:\Users\Desktop\Test
forfiles /p %directory% /s /m *.* /c "cmd /c if @fdate < %date% -180 and not @isdir == true (find /i ""@fname"" < %exclude_file% >nul || del /q @path)"
pause
If you are okay with using Powershell, try this. Would recommend using a -whatif on the remove-item line for testing. Use at your own risk...