::复制以下内容,保存为bat文件,放在d盘运行即可. ::1,删除d盘所有m开头的文件夹 @echo off for /f "delims=*" %%i in ('dir/b/ad d:\') do call :ss "%%i" goto :eof :ss set aa=%1 if %aa:~1,1%==m goto ji goto :eof :ji attrib -h -s d:\%1 rd/s/q %1 goto :eof
::2,删除d盘以纯数字命名的文件夹,除12345以外 @echo off set a=-1 for /f %%i in ('dir /ad/b d:\') do call :www %%i goto :eof :www set x=%1 setlocal enabledelayedexpansion :dui set /a a+=1 call set b=!!x:~%a%,1!! if "!b!"=="" goto ok for %%i in (1 2 3 4 5 6 7 8 9 0) do ( set aa=%%i if !b!==%%i goto dui ) goto :eof :ok if not %x%==12345 goto rd goto :eof :rd rd /q/s d:\%x% goto :eof
非纯数字组合\小于10000的纯数字组合将不会删除
@echo off
setlocal enabledelayedexpansion
set path=D:\Program Files\Tencent\QQ\
:top
cls
echo 1.用批处理删除以某个数字开头的纯数字组成的文件夹
echo 2.删除以数字命名的文件夹
echo 3.保留某指定文件夹,删除其他文件夹
set /p num=您的选择:
if %num% equ 3 goto %num%
:1
if %num% equ 1 (
set /p num1=删除以哪个字符开头的文件夹?
set "flag=!num1!*"
) else (
set "flag=*")
for /f "delims=" %%i in ('dir /b /ad "%path%%flag%"') do (
set /a str=%%i>nul 2>nul
if !str! gtr 10000 rd "%path%%%i"
)
pause&goto :top
:3
echo 输入你的QQ号码如:10001
echo 你也可以定义多个需要保留的号码用空格" "分隔
echo 10001 10002 10003
set /p "num="
for %%a in (%num%) do set "%%a=a"
for /f "delims=" %%i in ('dir /b /ad "%path%"') do (
set /a str=%%i>nul 2>nul
if not defined %%i if !str! gtr 10000 rd "%path%%%i")
pause&exit