从批处理文件中的txt文件中排除搜索

时间:2018-01-22 05:41:07

标签: batch-file

我有一个批处理文件Unregister.bat

    set UNREG="%~1"
    SET COMUnReg="%~dp0_tools_\bin\regasm.exe" /u
    SET FILES="%~dp0COMRegisteredNames.txt"

    FOR /F "delims= " %%a IN ('type %FILES%') DO (
    FOR /R "%UNREG%" %%f IN (*%%a*) DO (
        Echo UnRegistering %%f
        %COMUnReg% %%f
    )
)

txt文件包含要注销的文件名。

File1.dll
File2.dll

我将一个文件夹作为输入,其中包含所有dll文件以及一些不同的文件。现在我只想要取消注册dll文件,而不是任何其他具有相同名称的文件,如。

File2.dll.manifest

我想通过File2.dll搜索取消注册,但不想File2.dll.manifest搜索取消注册,任何想法如何做到这一点?

2 个答案:

答案 0 :(得分:0)

你可以尝试这样的事情:

@echo off
SET COMUnReg="%~dp0_tools_\bin\regasm.exe" /u
SET FILES="%~dp0COMRegisteredNames.txt"

FOR /F "delims= " %%f IN ('Type %FILES%') DO (
    If /I "%%~xf" EQU ".DLL" (
        Echo UnRegistering "%%f"
        %COMUnReg% "%%f"
    )

)
pause>nul & exit

答案 1 :(得分:0)

根据Stefan的评论,您只需使用*%%a*更改"*%%a"即可取消注册Something.dll,但不会Something.dll*