Batch file to delete folders older than N days except specific ones -
i'm looking make batch file delete profiles haven't been used in on 6 months while retaining specific ones such "administrator, default user, users, etc."
i've searched around , have found way remove older files/folders:
forfiles.exe /p d:\files /s /m . /d -7 /c "cmd /c del @file"
but there's no way of making exception "forfiles"
i've found way delete files/folders exceptions:
for %%i in (*.exe) if not "%%i"=="file name" del /q "%%i"
but that'll remove every file/folder , not older ones.
my scenario: take care of hundreds of workstations run winxp. there several users log in these computers , wouldn't want delete accounts. haven't logged in in while , exception of 3 or 4 permanent accounts in each workstation same. so, if no 1 has logged in administrator account in on 6 months, stay intact. can't drop forfiles of these workstations or other piece of software i'm limited on capabilities.
can help?
at first, make text file folder exceptions, put 1 folder per line in double quotes.
put exception file in %userprofile%
folder.
example exception.txt
:
"default" "default user" "all users"
batch
code:
for /f "delims=" %%a in ('forfiles /p "%userprofile%\.." /d -180 /c "cmd /c if @isdir==true echo @file"^|findstr /vig:"%userprofile%\exception.txt"') echo rd /s /q "%%~a"
look @ output , remove echo
command, if looks good.
forfiles
available in xp prof. or better, not xp home.
Comments
Post a Comment