删除*。*不包括一些扩展 [英] Delete *.* excluding some extensions
本文介绍了删除*。*不包括一些扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
即时试图使Windows上的批处理文件删除所有文件在当前目录中,但不包括4文件扩展名(登录,深发展,SDK,BAT)。
im trying to make a batch file on windows for deleting all the files in the current directory but excluding 4 file extensions (log, sdb, sdk, bat).
我试图在Windows上FORFILES命令,但该删除我的当前文件夹中(即使是bat文件)的一切。我的命令是:
I have tried the Forfiles command on windows but this delete everything on my current folder (even the bat file). My command is:
@ECHO OFF
FORFILES /M *.* /C "cmd /c IF NOT @ext=="sdb" (IF NOT @ext=="sbk" (IF NOT @ext=="log" (IF NOT @ext=="bat" DEL @FILE)))" /Q
我怎样才能使它工作?
How can I make it work?
非常感谢!
推荐答案
- 内部报价必须以
转义\\
- 您可能希望
IF / I
(不区分大小写)选项 - 您应该使用@ISDIR排除目录
- DEL / Q选项最后一次报价后,应该是最后的报价之前,但它并不需要
- 不需要括号
- FORFILES /不需要-M选项,因为你的面具为所有文件
- internal quotes must be escaped with
\
- you probably want
IF /I
(case insensitive) option - you should use @ISDIR to exclude directories
- DEL /Q option was after last quote, should be before last quote, but it isn't needed
- parentheses are not needed
- FORFILES /M option isn't needed since your mask is "all files"
这应该工作
@echo off
forfiles /c "cmd /c if @isdir equ FALSE if /i not @ext==\"sdb\" if /i not @ext==\"sbk\" if /i not @ext==\"log\" if /i not @ext==\"bat\" del @file"
但上面的很慢,而且可以肯定的是很多类型。
But the above is very slow, and it sure is a lot to type.
以下是更简单和更快。
@echo off
for /f %%F in ('dir /b /a-d ^| findstr /vile ".sdb .sbk .log .bat"') do del "%%F"
这篇关于删除*。*不包括一些扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文