如何删除 *.* 排除某些扩展名? [英] How to delete *.* excluding some extensions?
本文介绍了如何删除 *.* 排除某些扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Windows 上制作一个批处理文件,用于删除当前目录中的所有文件,但不包括 4 个文件扩展名(log、sdb、SDK、bat).
I'm 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 选项,因为您的掩码是所有文件"
这应该有效
@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 "delims=" %%F in ('dir /b /a-d ^| findstr /vile ".sdb .sbk .log .bat"') do del "%%F"
这篇关于如何删除 *.* 排除某些扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文