简体   繁体   English

删除包含字符串的系统文件

[英]Delete System Files containing string

I am trying to write a batch file that will examine a given directory, read each file for a given string "Example" and then delete any files that contain the string. 我正在尝试编写一个批处理文件,该文件将检查给定目录,读取给定字符串“ Example”的每个文件,然后删除包含该字符串的所有文件。 The files are also System Files so I don't know what the exact extension is or if that matters (maybe you can just omit a file type filter and have it read all files?). 这些文件也是系统文件,因此我不知道确切的扩展名是什么,或者这是否重要(也许您可以省略文件类型过滤器并让其读取所有文件?)。 Some of the files will be locked from reading as well so it needs to handle access denial errors if that occurs, not sure how batch files handle that. 一些文件也将被锁定以防止读取,因此如果发生访问拒绝错误,则需要处理访问拒绝错误,不确定批处理文件如何处理该错误。

Update What I ended up using was this: 更新我最终使用的是:

for /f "eol=: delims=" %F in ('findstr /m monkey *.txt') do del "%F" 为/ f“ eol =:delims =”%F in('findstr / m monkey * .txt')做del“%F”

Found here: Search and then delete depending on whether files contain a string 在这里找到: 根据文件是否包含字符串搜索然后删除

I ended up finding it shortly after I posted this. 发布此消息后不久,我最终找到了它。

Try something like this: 尝试这样的事情:

@echo off

cd "C:\some\where"
for /f %%f in ('dir /b /a:-d *') do (
  findstr "Example" "%%~ff" && (
    attrib -r -s -h "%%~ff"
    del /q "%%~ff"
  )
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM