本帖最后由 七剑下面条 于 2018-12-11 13:35 编辑
如题,我有一个代码删除除标记文件夹外的指定文件夹,但是代码太麻烦了,能精简一下吗- @echo off&SETLOCAL enabledelayedexpansion
- rem 要排除的文件夹名字放在exception变量里面,使用“;”分割
- set "exception=$RECYCLE.BIN;Documents and Settings;Program Files;Program Files (x86);ProgramData;Recovery;System Volume Information;Users;Windows;efi;boot;PerfLogs;msocache"
- for /f "delims=" %%a in ('dir G:\ /ad /b') do (
- rem bool重新赋值标志删除,false为不删除标志
- set bool=true
- for /f "delims=; tokens=1-13" %%i in ("%exception%") do (
- if "%%a"=="%%i" (
- set bool=false
- break
- )
- if "%%a"=="%%j" (
- set bool=false
- break
- )
- if "%%a"=="%%k" (
- set bool=false
- break
- )
- if "%%a"=="%%l" (
- set bool=false
- break
- )
- if "%%a"=="%%m" (
- set bool=false
- break
- )
- if "%%a"=="%%n" (
- set bool=false
- break
- )
- if "%%a"=="%%o" (
- set bool=false
- break
- )
- if "%%a"=="%%p" (
- set bool=false
- break
- )
- if "%%a"=="%%q" (
- set bool=false
- break
- )
- if "%%a"=="%%r" (
- set bool=false
- break
- )
- if "%%a"=="%%s" (
- set bool=false
- break
- )
- if "%%a"=="%%t" (
- set bool=false
- break
- )
- if "%%a"=="%%u" (
- set bool=false
- break
- )
- )
- if !bool!==true echo %%a,!bool!
-
- )
- pause >nul
复制代码
|