标题: [文本处理] 批处理findstr排除文本,文本文件内容为空会出错 [打印本页]
作者: hentai87 时间: 2020-6-3 20:18 标题: 批处理findstr排除文本,文本文件内容为空会出错
- for /f "delims=" %%i in ('findstr /g:black_list.txt /v list.txt 2^>nul') do (
- echo %%b\Bin\x64\DISM10\dism.exe /image:%%b /Remove-Capability /CapabilityName:"%%i"
- %%b\Bin\x64\DISM10\dism.exe /image:%%b\Mount\Install /Remove-Capability /CapabilityName:"%%i"
- )
复制代码
black_list.txt 内容为空,就失效了
怎么解决呢,
虽然black_list.txt随便写点就解决了,但这bat不完美
作者: Batcher 时间: 2020-6-3 23:19
回复 1# hentai87
在for命令上面加一句:- more "black_list.txt" | findstr "." >nul 2>&1 || goto :eof
复制代码
作者: hentai87 时间: 2020-6-4 10:34
回复 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
作者: flashercs 时间: 2020-6-4 11:25
- findstr /g:black_list.txt /v list.txt 2>nul
- if errorlevel 2 (
- for /f "delims=" %%i in (list.txt) do (
- echo %%b\Bin\x64\DISM10\dism.exe /image:%%b /Remove-Capability /CapabilityName:"%%i"
- %%b\Bin\x64\DISM10\dism.exe /image:%%b\Mount\Install /Remove-Capability /CapabilityName:"%%i"
- )
- ) else (
- for /f "delims=" %%i in ('findstr /g:black_list.txt /v list.txt 2^>nul') do (
- echo %%b\Bin\x64\DISM10\dism.exe /image:%%b /Remove-Capability /CapabilityName:"%%i"
- %%b\Bin\x64\DISM10\dism.exe /image:%%b\Mount\Install /Remove-Capability /CapabilityName:"%%i"
- )
- )
复制代码
作者: hentai87 时间: 2020-6-4 14:44
本帖最后由 hentai87 于 2020-6-4 14:49 编辑
自己弄错了,解决了
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |