Search and delete files owned by selected user through batch -
my objective is: - find files owned selected user - delete them
my current code:
@echo off /f %%f in ('dir /b /s') call :delete_file %%f goto :eof :delete_file ( set var=%1 dir /q %var%| find "\user" )
i'm looping files in current directory, i'm calling :delete_file parameter %%f (file path), in :delete_file i'm setting var first received parameter (%1 - file path). , now, i'm parsing again file (with /q paramter - output owner) in search of owner. question is, how set output of:
dir /q %var%| find "\user"
to variable? if output null, file not owned selected user, otherwise can delete file. how check this?
this should echo del command files matching text
if happy remove echo
keyword , run real.
i made text compare case insensitive.
@echo off /f %%f in ('dir /b /s /a-d') ( dir /q "%%f"| find /v ":\" |find /i "%computername%\user">nul && echo del "%%f" )
Comments
Post a Comment