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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:30:39  来源:igfitidea点击:

Windows CMD Search and Delete file by name

windowsfilecmddelete-file

提问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 originalin the name. Is this possible?

我想要一个命令来搜索媒体中的所有文件夹并删除original名称中包含的任何图像。这可能吗?

回答by Magoo

del /s ...\media\*original*.jpg

should delete all files with originalin their name, extension .jpgfrom ...\mediaand 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.

如果要在批处理脚本中使用它,请替换%%%