本帖最后由 hfxiang 于 2022-8-16 20:04 编辑
- @echo off
- @rem 只保留以 111 和 222 为开头的文件夹,以 333 和 444 为开头的文件,以及所有.ini 和.exe 文件。
- @setlocal enableDelayedExpansion
-
- for /f "delims==" %%a in ('set _retain_ 2^>nul') do set "%%a="
- set "_retain_Folder_111=True"
- set "_retain_Folder_222=True"
- set "_retain_File_333=True"
- set "_retain_File_444=True"
- set "_retain_File_.ini=True"
- set "_retain_File_.exe=True"
-
- for /r %%a in (.,*) do (
- set "Dir_a=%%~aa"
- set "Dir_x=%%~xa"
- set "Dir_n=%%~na"
- set "Dir_n=!Dir_n:~0,3!"
- if /i not "[%cd%]"=="[%%~fa]" if /i not "[%~f0]"=="[%%~fa]" if defined Dir_a if "[!Dir_a:~0,1!]"=="[d]" (
- if not defined _retain_Folder_!Dir_n! rd /q/s "%%~fa"
- ) else (
- set "_retain_File_T="
- if defined _retain_File_!Dir_n! set "_retain_File_T=True"
- if defined _retain_File_!Dir_x! set "_retain_File_T=True"
- if not defined _retain_File_T del/f/s/q "%%~fa"
- )
- )
-
- endlocal
- echo;&pause
- exit /b
复制代码
|