Windows CMD 按名称搜索和删除文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16552056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows CMD Search and Delete file by name
提问by Ozzy
I have a website dump which has about half a gig worth of images which have been converted to various file sizes. The structure goes like:
我有一个网站转储,其中包含大约半个演出价值的图像,这些图像已转换为各种文件大小。结构如下:
media/
1/
1.original.jpg
1.large.jpg
1.medium.jpg
1.small.jpg
2/
2.original.jpg
2.large.jpg
2.medium.jpg
2.small.jpg
etc...
I want a command that will search through all folders in media and delete any image which has original
in the name. Is this possible?
我想要一个命令来搜索媒体中的所有文件夹并删除original
名称中包含的任何图像。这可能吗?
回答by Magoo
del /s ...\media\*original*.jpg
should delete all files with original
in their name, extension .jpg
from ...\media
and all its subdirectories.
要删除所有文件与original
在他们的名字,扩展.jpg
来自...\media
及其所有子目录。
Obviously, use with extreme caution... If you desire to see what you are going to delete first before deleting it use
显然,使用时要格外小心...如果您想在删除之前先查看要删除的内容,请使用
dir /s ...\media\*original*.jpg
回答by Ansgar Wiechers
Try with something like this:
尝试这样的事情:
for /R C:\...\media %f in (*original*.jpg) do del /q "%~ff"
Replace %
with %%
if you want to use this in a batch script.
如果要在批处理脚本中使用它,请替换%
为%%
。