创建批处理文件以删除特定文件

发布于 2024-12-11 00:02:31 字数 259 浏览 0 评论 0原文

起初,我知道这个问题可能存在,但乍一看我没有找到我正在寻找的答案。

我在创建批处理文件时遇到问题,该文件应删除多个文件,并将其特定文件格式作为参数给出。这些文件所在的文件夹被定义为第一个参数。只读文件、隐藏文件和系统文件也应该删除。

到目前为止,我有这样的事情:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诺曦 2024-12-18 00:02:32

怎么样...

CD /D %1
DEL *.%2  /F /A:H /A:S

CD 旁边的 /D 确保它也更改当前驱动器。默认情况下,无论您想去哪里,CD 都会始终保留在同一个驱动器中。

那么,if exit 就没有意义了。如果没有要删除的内容,DEL 不会删除任何内容。

我不确定 *.%2 是否真的是您想要的,因为它只会匹配没有名称且具有特定扩展名的文件。您可能只需要 %2 确实如此。

如果这不起作用,请告诉我们会发生什么。您告诉我们预期的结果,即它应该删除给定目录中与给定模式匹配的文件。告诉我们会发生什么。

How about...

CD /D %1
DEL *.%2  /F /A:H /A:S

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 if *.%2 is really what you want, because it will only match files with no name with a certain extension. You probably want only %2. It is.

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.

柏拉图鍀咏恒 2024-12-18 00:02:32

http://forums.techarena.in/windows-server-help/621875.htm 。

del /s *.tmp *.temp *.dmp

下次,先研究一下你的问题

http://forums.techarena.in/windows-server-help/621875.htm

del /s *.tmp *.temp *.dmp

Next time, research your question first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文