Your code needs a few touchups. The pipe operator needs to be escaped by the batch escape character
^ and when using quotations within the parentheses for a command, the
usebackq option must be specified.
for /f "usebackq" %%i in (`dir /s /b ^| find "lock"`) do echo %%i
Command Line Format:
for /f "usebackq" %i in (`dir /s /b ^| find "lock"`) do echo %i
del and any of its options when you want it to actually delete the files. Note the double percent signs are needed when used within a bat file, single when used directly on the command line.
Another method is to use the
forfiles /m *lock* /s /c "cmd /c echo @file"
Note, both of these methods will also delete any folders that contain the search term
lock. Additional steps would be needed to be taken to prevent this.