Windows 如何将.txt中的某些内容从For中排除?

Windows 如何将.txt中的某些内容从For中排除?,windows,for-loop,batch-file,if-statement,cmd,Windows,For Loop,Batch File,If Statement,Cmd,我制作了以下脚本,用于显示目标中没有指定文件夹的所有本地用户 我想为我不想显示的用户创建一个exlusion文本文件 我真的很确定如何才能做到这一点 这是我的密码: @echo off set BackupDest=D:\backup echo Destination folder missing for the following user(s): for /D %%I in ("%HomeDrive%\users\*") do if not exist "%BackupDest%\%%~

我制作了以下脚本,用于显示目标中没有指定文件夹的所有本地用户

我想为我不想显示的用户创建一个exlusion文本文件

我真的很确定如何才能做到这一点

这是我的密码:

@echo off

set BackupDest=D:\backup

echo Destination folder missing for the following user(s):
for /D %%I in ("%HomeDrive%\users\*") do if not exist "%BackupDest%\%%~nI\" (
echo %%~nI
)
要排除的用户命名文件夹可以添加到
exclude\u user.txt
。该文件位于脚本目录中,例如
%~dp0
。 如果文件不存在,则创建该文件时会有一行包含公共,您可能不想备份该行

findstr
的参数当前设置为不区分大小写的文本精确匹配

dir
将查找未隐藏的文件夹,以便不会输出特殊命名文件夹,如
Default

@echo off
setlocal
set "BackupDest=D:\backup"

if not exist "%~dp0exclude_user.txt" > "%~dp0exclude_user.txt" echo Public

echo Destination folder missing for the following user(s) :

for /f "tokens=*" %%I in (
    'dir /a:d-h /b "%HomeDrive%\users\*" ^| findstr /b /e /i /l /v /g:"%~dp0exclude_user.txt"'
) do if not exist "%BackupDest%\%%~nxI\" (
    echo %%~nxI
)