batch-file - 通过批处理文件创建没有重复的元素集合
问题描述
我在for
生成结果数组的自定义工具上运行多个循环。
我需要将它们展平为一个没有重复的集合。
我的第一个想法是创建键是项目的数组,见下文。但这是之后迭代的噩梦......:
set apps=
for /d %%s in (".\manifests\*.xml") do (
for /f "tokens=*" %%g in ('xml sel -t -v "\apps\app" %cd%\manifests\%%s') do (
echo Found app - %%g [inside %%s]
rem First idea below:
set apps[%%g]=true
)
)
rem How to iterate apps afterwards?
解决方案
刚刚搞定:
set apps=
set apps_defined=
for /d %%s in (".\manifests\*.xml") do (
for /f "tokens=*" %%g in ('xml sel -t -v "\apps\app" %cd%\manifests\%%s') do (
echo Found app - %%g [inside %%s]
if not "apps_defined[%%g]"=="true" (
if not "!apps!"=="" set apps=!apps!,
set apps=!apps!%%g
)
set apps_defined[%%g]=true
)
)
推荐阅读
- node.js - sveltekit 中未定义的 process.env 环境变量
- deep-learning - 梯度累积问题
- java - 字符串未显示在输出中
- python - 如何在 Python 中的密度颜色图上绘制密度线图
- visual-c++ - 尝试构建调试时来自 boost 的编译器错误
- java - 有没有办法在休眠实体 xml 映射中访问 Java 常量?
- swift - 将带有参数的 Swift 函数分配给 Objective-C 属性时出现奇怪的错误消息
- python - 尝试在 AWS 上执行转录作业时出现 [ERROR] KeyError: 's3' in Lambda 函数
- typescript - 导出默认推断采取捷径
- r - R 错误:无法将类型“闭包”强制转换为“整数”类型的向量