批处理脚本删除文件containining某些字符 [英] batch script delete file containining certain chars
问题描述
我有一批几乎没有任何经验,但现在我需要一个脚本来删除的包含的在其名称中的某些字符从文件夹中的及其子文件夹的Windows上的所有文件64.我只是做批量简单的事情,像
I have almost no experience in batch, but now I need a script to delete all files that contain certain characters in their names from a folder and its subfolders on Windows 64. I only did simple things in batch like
del "C:\TEST\TEST2\*.TXT"
但我不知道如何执行我所需要的过滤。
可能有人帮助我实现这个使用批处理?
But I have no idea how to perform the filtering I need. Could someone help me to achieve this using batch?
修改更确切地说,问题是如何辨别真假一批包括子文件夹?
EDIT more exactly, the question is "how to tell batch to include subfolders?"
推荐答案
试试这个:
@echo off & setlocal
set "MySearchString=X"
for /f "delims=" %%i in ('dir /b /s /a-d ^| findstr /i "%MySearchString%"') do echo del "%%~i"
设置变量 MySearchString
来的字符或字符串搜索和删除回声
命令,如果输出OK。
Set the variable MySearchString
to the character or string to search and remove the echo
command, if the output is OK.
您还可以指定 MySearchString
仅文件名:
You can also specify the MySearchString
for the file name only:
@echo off & setlocal
set "MySearchString=T"
for /r %%a in (*) do for /f "delims=" %%i in ('echo("%%~na" ^| findstr /i "%MySearchString%"') do echo del "%%~fa"
这篇关于批处理脚本删除文件containining某些字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!