Andy Alvarez
Andy Alvarez

Reputation: 51

String Exist Check and Echo to File

For each folder in this directory:

"F:\!Storage\!FS Addons\!X-Plane\!Tools\!Ortho4XP\Tiles"

Here are example folders in the above directory (the numbers are GPS coordinates):

zOrtho4XP_+65-023
zOrtho4XP_+65-024
zOrtho4XP_+65-025
zOrtho4XP_+66-015
zOrtho4XP_+66-016

Those zOrtho4XP_* folders contain satellite imagery which will be overlayed on the default scenery of the X-Plane 11 Flight Simulator.

In order for the satellite images to appear in the simulator, their folder names need to be added to the scenery_packs.ini file, which resides in
"E:\X Plane 11\X-Plane 11\Custom Scenery\scenery_packs.ini"

Here is an example of the scenery_packs.ini file: Note how it contains the folder names of the folders containing the satellite imagery

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/

These zOrtho4XP_* folders are downloaded in batches and some batches contain dozens of these zOrtho4XP_* folders, and each of those folder names have to be added to the scenery_packs.ini file. That's what I'm trying to avoid manually doing, because I'm going to be doing a lot of this in the coming weeks and I prefer to not have to manually add those folders line by line; it would be hundreds, if not over 1,000.

I've managed to scribble this up, but it's as far as my knowledge goes with batch:

@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

Upvotes: 2

Views: 60

Answers (1)

michael_heath
michael_heath

Reputation: 5372

@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%"

This will get each subfolder name in the root of %target%. Findstr will search in the %destination% ini file for the folder name pattern. If failure, then the folder name pattern is echoed to %destination% file.

The ^ is a line continuation character as a line is long.

Upvotes: 2

Related Questions