创建批处理文件以删除特定文件
起初,我知道这个问题可能存在,但乍一看我没有找到我正在寻找的答案。
我在创建批处理文件时遇到问题,该文件应删除多个文件,并将其特定文件格式作为参数给出。这些文件所在的文件夹被定义为第一个参数。只读文件、隐藏文件和系统文件也应该删除。
到目前为止,我有这样的事情:
CD %1
IF EXIST *.%2 DEL *.%2 /F /A:H /A:S
但这没有得到应有的结果...... 有人可以帮助我吗?
At first, I know this question probably exists, but on first sight I didn't find the answer I was looking for.
I'm having a problem creating a batch-file that should delete multiple files with their specific file format given as a parameter. The folder where these files should be is defined as the first parameter. Read-Only, hidden and system files should be deleted too.
So far I have something like this:
CD %1
IF EXIST *.%2 DEL *.%2 /F /A:H /A:S
But this doesn't has the result it should have...
Can someone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样...
CD 旁边的
/D
确保它也更改当前驱动器。默认情况下,无论您想去哪里,CD 都会始终保留在同一个驱动器中。那么,
if exit
就没有意义了。如果没有要删除的内容,DEL
不会删除任何内容。我不确定确实如此。*.%2
是否真的是您想要的,因为它只会匹配没有名称且具有特定扩展名的文件。您可能只需要%2
。如果这不起作用,请告诉我们会发生什么。您告诉我们预期的结果,即它应该删除给定目录中与给定模式匹配的文件。告诉我们会发生什么。
How about...
The
/D
by the CD makes sure it also changes the current drive. By default CD will always stay in the same drive, no matter where you want to go.Then, the
if exist
is pointless. If there is nothing to delete,DEL
won't delete anything.I'm not sure ifIt is.*.%2
is really what you want, because it will only match files with no name with a certain extension. You probably want only%2
.If that doesn't work, please tell us what happens. You told us the expect result, namely that it should delete files in a given directory matching a given pattern. Tell us what happens instead.
http://forums.techarena.in/windows-server-help/621875.htm 。
下次,先研究一下你的问题
http://forums.techarena.in/windows-server-help/621875.htm
Next time, research your question first.