Loop subfolders to join all ASCII files then export as a single file
Hi,
I am having issues trying to merge all ASCII files in subfolders to then export to the root (master folder) the combined file from each subfolder. I cant use RECURSIVE and the FILENAME_MASK=".." does not seem to work. This code starts to loop over the xyz files then gives the error that no elevation data is present at the export. It then goes back round and tries to loop again and crashes globalmapper if i exit.
DIR_LOOP_START DIRECTORY="%MASTER_FOLDER%*"
// Loop through Subfolders
DIR_LOOP_START DIRECTORY="%MASTER_FOLDER%*" FILENAME_MASK=".."
IMPORT_ASCII FILENAME="%FNAME_W_DIR%" TYPE="POINT_ONLY" FILENAME_MASK="*.XYZ" \
PROJ_NAME="TM_WGS84" COORD_DELIM="AUTO" COORD_FORMAT="DECIMAL" COORD_ORDER="X_FIRST" \
INC_COORD_LINE_ATTRS="YES" COL_HEADERS="NO" INC_ELEV_COORDS="YES" \
CREATE_AREAS_FROM_LINES="NO" SKIP_COLUMNS="0" SKIP_ROWS="0" \
LINE_TYPE="Unclassified Line Feature" ELEV_UNITS="METERS"
DIR_LOOP_END
EXPORT_ELEVATION FILENAME="%MASTER_FOLDER%%FNAME_NO_EXT%_cropped.asc" TYPE=ARCASCIIGRID POLYGON_CROP_NAME="Crop-TSF-Border"
UNLOAD_ALL
DIR_LOOP_END
Any help would be greatly appreciated.
I am running V23.1
Comments
-
I used CoPilot (M365) and uploaded the Global Mapper Scripting reference and it output this (untested):
GLOBAL_MAPPER_SCRIPT VERSION=1.00
DEFINE_VAR NAME="MASTER_FOLDER" VALUE="C:\\Path\\To\\Your\\MasterFolder\\"
DIR_LOOP_START DIRECTORY="%MASTER_FOLDER%" FILENAME_MASKS="*"
// Define output filename using parent folder name
DEFINE_VAR NAME="OUT_NAME" VALUE="%DIR%" FILENAME_PIECE="PARENT_DIR"
// Import all XYZ files in the current subfolder
IMPORT_ASCII FILENAME="%DIR%*.xyz" TYPE="POINT_ONLY" \
COORD_DELIM="AUTO" COORD_FORMAT="DECIMAL" COORD_ORDER="X_FIRST" \
INC_COORD_LINE_ATTRS="YES" COL_HEADERS="NO" INC_ELEV_COORDS="YES" \
CREATE_AREAS_FROM_LINES="NO" SKIP_COLUMNS="0" SKIP_ROWS="0" \
ELEV_UNITS="METERS"
// Export merged elevation data to root folder
EXPORT_ELEVATION FILENAME="%MASTER_FOLDER%%OUT_NAME%_merged.asc" TYPE=ARCASCIIGRID
UNLOAD_ALL
DIR_LOOP_END
Key Fixes and Notes
FILENAME_MASKS="*"
inDIR_LOOP_START
ensures it loops over subfolders.%DIR%*.xyz
loads all XYZ files in the current subfolder.DEFINE_VAR
withFILENAME_PIECE="PARENT_DIR"
extracts the subfolder name for naming the output file.- Avoids recursion and uses only one
DIR_LOOP_START
.
Categories
- 12.9K All Categories
- 5.7K Features Discussion
- 346 Downloading Imagery
- 1.3K Elevation Data
- 385 Georeferencing Imagery Discussion
- 645 GM Script Language
- 54 User Scripts
- 115 GPS Features
- 419 Projection Questions
- 831 Raster Data
- 1.4K Vector Data
- 6.6K Support
- 180 Announcement and News
- 928 Bug Report
- 561 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 576 Other Discussion
- 132 GIS Data Sources
- 27 Global Mapper Showcase
- 243 How I use Global Mapper
- 108 Global Mapper Forum Website