[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 批处理findstr排除文本,文本文件内容为空会出错

  1. for /f "delims=" %%i in ('findstr /g:black_list.txt /v list.txt 2^>nul') do (
  2. echo %%b\Bin\x64\DISM10\dism.exe /image:%%b /Remove-Capability /CapabilityName:"%%i"
  3. %%b\Bin\x64\DISM10\dism.exe /image:%%b\Mount\Install /Remove-Capability /CapabilityName:"%%i"
复制代码
black_list.txt 内容为空,就失效了
怎么解决呢,

虽然black_list.txt随便写点就解决了,但这bat不完美

本帖最后由 hentai87 于 2020-6-4 14:49 编辑

自己弄错了,解决了

TOP

  1. findstr /g:black_list.txt /v list.txt 2>nul
  2. if errorlevel 2 (
  3.   for /f "delims=" %%i in (list.txt) do (
  4.     echo %%b\Bin\x64\DISM10\dism.exe /image:%%b /Remove-Capability /CapabilityName:"%%i"
  5.     %%b\Bin\x64\DISM10\dism.exe /image:%%b\Mount\Install /Remove-Capability /CapabilityName:"%%i"
  6.   )
  7. ) else (
  8.   for /f "delims=" %%i in ('findstr /g:black_list.txt /v list.txt 2^>nul') do (
  9.     echo %%b\Bin\x64\DISM10\dism.exe /image:%%b /Remove-Capability /CapabilityName:"%%i"
  10.     %%b\Bin\x64\DISM10\dism.exe /image:%%b\Mount\Install /Remove-Capability /CapabilityName:"%%i"
  11.   )
  12. )
复制代码
微信:flashercs
QQ:49908356

TOP

回复 2# Batcher


    试了,没用,下面是完整代码

@echo off
cd /d %~dp0
%1 start "" mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&exit

setlocal EnableDelayedExpansion

for /f "delims=:" %%a in ('findstr /n msmg设置 ..\set.txt') do set n=%%a
        for /f "skip=%n% delims=" %%b in (..\set.txt) do (
        for /f "tokens=1,2* delims=: " %%A in ('%%b\Bin\x64\DISM10\dism.exe /image:%%b\Mount\Install /Get-ProvisionedAppxPackages') do (
        if "%%A"=="PackageName" (
cd. >list.txt
echo %%B>>list.txt

more "black_list.txt" | findstr "." >nul 2>&1 || goto :eof
        for /f "delims=" %%i in ('findstr /g:black_list.txt /v list.txt 2^>nul') do (
%%b\Bin\x64\DISM10\dism.exe /image:%%b\Mount\Install /Remove-ProvisionedAppxPackage /PackageName:"%%i"
))))
endlocal
pause
exit /b

TOP

回复 1# hentai87


在for命令上面加一句:
  1. more "black_list.txt" | findstr "." >nul 2>&1 || goto :eof
复制代码
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

返回列表