批处理文件以删除文件名以特定字符结尾的文件 [英] batch file to delete files filename ending in particular characters

查看:432
本文介绍了批处理文件以删除文件名以特定字符结尾的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个批处理文件,该文件将从目录中以特定编号结尾的目录中删除所有文件。



例如删除所有类型的文件.js来自文件名以1.1.1.0结尾的文件夹



关于我如何编写这样的批处理文件来实现这一目标的任何提示?



如果我想删除所有未以1.1.1.0结尾的.js类型的文件,会有什么不同?

解决方案

所以,看来您可以这样做:

  del * 1.1.1.0 .js 

或者,您可以这样编写批处理文件(tmp.bat):

  del *%1.js 

并命名为:

  tmp.bat 1.1.1.0 

但这似乎有点过分?



我是否缺少某些东西? p>

或者,我想您可能想要以下内容:

  del%1 \ *%2.js 

您会这样称呼:

  tmp.bat文件夹名称1.1.1.0 

您可能还希望传递'/ F'标志以删除,以确保它删除了只读文件...



如果您也想在子目录中执行文件,则批处理文件应如下所示:

  echo del / f / s%1\ *%2.js 

再次,其中%1是要开始的文件夹名称,%2是要删除的数字...



要执行所有操作但要给定数字,您可以执行以下操作:

  attrib + h *%1.js 
del / q *
attrib -h *%1.js

到从给定的文件夹中删除所有但给定编号的东西,您可以这样做:

  pushd%1 
attrib + h *%2.js
del / q *
attrib -h *%2.js
popd

其中%1是文件夹,%2是数字


I am looking to write a batch file that will remove all files from a directory where there file name ends in a particular number.

Eg delete all files of type .js from a folder where the filename end in 1.1.1.0

Any tips as to how I may write such a batch file to achieve this?

How would it be different if I wanted to delete all of the files of type .js that didn't end in 1.1.1.0?

解决方案

So, it seems you could just do:

del *1.1.1.0.js

Or, you could write a batch file (tmp.bat) like this:

del *%1.js

And call it:

tmp.bat 1.1.1.0

But that seems like overkill?

Is there something I'm missing?

Or, I guess you might want something like:

del %1\*%2.js

Which you would call as:

tmp.bat folderName 1.1.1.0

You may also want to pass a '/F' flag to delete, to make sure it deletes readonly files...

If you wanted to do files in subdirectories as well, the batch file could look like this:

echo del /f /s %1\*%2.js

Again, where %1 is the folder name to start from and %2 is the number you want to delete...

To do everything BUT a given number, you could do something like this:

attrib +h *%1.js
del /q *
attrib -h *%1.js

To delete everything BUT a given number, from a given folder you could do this:

pushd %1
attrib +h *%2.js
del /q *
attrib -h *%2.js
popd

Where %1 is the folder and %2 is the number

这篇关于批处理文件以删除文件名以特定字符结尾的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆