【问题标题】:How to get lib files list under specific path in bat?如何在bat中获取特定路径下的lib文件列表?
【发布时间】:2021-10-14 17:40:31
【问题描述】:

这是我的 bat 文件:

setlocal EnableDelayedExpansion
set DebugLibNames=
for /f "delims=" %%a in ('"dir /s/b *.lib ..\3rdlib\Debug\ 2>nul"') do (
    set DebugLibNames=%%DebugLibNames%%, %%a
)

echo DebugLibNames:%DebugLibNames%

call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
lib.exe /OUT:world.lib %DebugLibNames%

pause

我想要的是获取一个 lib 文件名列表,然后用 lib.exe 将它们打包到一个大 lib 中。

但是,DebugLibNames 是空的,我该如何解决?

【问题讨论】:

  • 将行 set DebugLibNames=%%DebugLibNames%%, %%a 替换为 set DebugLibNames=!DebugLibNames!, %%a...
  • 还要注意命令行长度有限制,因此您需要注意目录树的深度和其中的 lib 文件数量。

标签: windows batch-file cmd command-line


【解决方案1】:

这未经测试,但似乎可能有效或接近。 :-)

powershell -NoLogo -NoProfile -File 'Do-It.ps1'

=== Do-It.ps1

$DebugLibNames = Get-ChidItem -Path @('.', '..\3rdlib\Debug') -Filter '*.lib' -ErrorAction SilentlyContinue
Write-Host "DebugLibNames:$($DebugLibNames -join ', ')"
& "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
& lib.exe /OUT:world.lib $($DebugLibNames -join ', ')"

pause

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多