batch-file - 字符串存在检查并回显到文件
问题描述
对于此目录中的每个文件夹:
"F:\!Storage\!FS Addons\!X-Plane\!Tools\!Ortho4XP\Tiles"
以下是上述目录中的示例文件夹(数字为 GPS 坐标):
zOrtho4XP_+65-023
zOrtho4XP_+65-024
zOrtho4XP_+65-025
zOrtho4XP_+66-015
zOrtho4XP_+66-016
这些zOrtho4XP_*
文件夹包含卫星图像,这些图像将覆盖在 X-Plane 11 Flight Simulator 的默认风景上。
为了让卫星图像出现在模拟器中,需要将它们的文件夹名称scenery_packs.ini
添加到文件中,该文件位于"E:\X Plane 11\X-Plane 11\Custom Scenery\scenery_packs.ini"
以下是该scenery_packs.ini
文件的示例:注意它如何包含包含卫星图像的文件夹的文件夹名称
SCENERY_PACK Custom Scenery/zOrtho4XP_+65-023/
SCENERY_PACK Custom Scenery/zOrtho4XP_+65-024/
SCENERY_PACK Custom Scenery/zOrtho4XP_+65-025/
SCENERY_PACK Custom Scenery/zOrtho4XP_+66-015/
SCENERY_PACK Custom Scenery/zOrtho4XP_+66-016/
这些zOrtho4XP_*
文件夹是分批下载的,有些批次包含几十个这样的zOrtho4XP_*
文件夹,每个文件夹名称都必须添加到scenery_packs.ini
文件中。这就是我要避免手动执行的操作,因为在接下来的几周内我将做很多这样的事情,而且我更喜欢不必逐行手动添加这些文件夹;如果不超过 1,000 人,那将是数百人。
我已经设法把它写下来了,但据我所知,这是批处理:
@echo off
setlocal
set "target=F:\!Storage\!FS Addons\!X-Plane\!Tools\!Ortho4XP\Tiles"
set "destination=E:\X Plane 11\X-Plane 11\Custom Scenery\scenery_packs.ini"
for %%a in ("%target%") do (
findstr %%~nxA
if exist IGNORE
)else(
echo %%~nxA >> %destination% )
endlocal
pause
解决方案
@echo off
setlocal
set "target=F:\!Storage\!FS Addons\!X-Plane\!Tools\!Ortho4XP\Tiles"
set "destination=E:\X Plane 11\X-Plane 11\Custom Scenery\scenery_packs.ini"
(
for /d %%A in ("%target%\*") do @(
>nul findstr /c:"SCENERY_PACK Custom Scenery/%%~nxA/" "%destination%" ^
|| echo SCENERY_PACK Custom Scenery/%%~nxA/
)
) >> "%destination%"
这将获得根目录中的每个子文件夹名称%target%
。
Findstr
将在%destination%
ini 文件中搜索文件夹名称模式。如果失败,则将文件夹名称模式回显到%destination%
文件。
这^
是一个行继续字符,因为一行很长。
推荐阅读
- r - 如何从数据集中删除多个年月
- python - 使用 Mathplotlib.pyplot 不会显示 Scipy 插值网格数据
- python-2.7 - AttributeError:“模块”对象没有属性“Ed25519Key”
- asp.net - 关于 IHttpModule 实现的私有字段的问题
- if-statement - 无法让滑块在间隔之间打印不同的文本
- reactjs - 使用 Gatsby 预览 Kentico Cloud 内容
- sql - 计算熊猫数据框中的不同值
- rust - 为什么你可以在比赛中使用以前未声明的名字?
- java - 反应式 WebSocketClient 数据发布
- rss - Podcast RSS 验证但不播放