我想删除当前目录中名称中不包含字符串“sample”的所有文件.
例如,
test_final_1.exe test_initial_1.exe test_sample_1.exe test_sample_2.exe
我想删除名称中包含样本的文件以外的所有文件.
for %i in (*.*) do if not %i == "*sample*" del /f /q %i Is the use of wild card character in the if condition allowed? Does,(*.*) represent the current directory?
谢谢.
最简单的方法是使用带有/ V选项的FIND或FINDSTR来查找不包含字符串的名称,使用/ I选项进行不区分大小写的搜索.切换到FOR / F并将DIR的管道结果发送到FIND.
for /f "eol=: delims=" %F in ('dir /b /a-d * ^| find /v /i "sample"') do del "%F"
如果在批处理文件中使用,则将%F更改为%% F.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。