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

Tagged:

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="*" in DIR_LOOP_START ensures it loops over subfolders.
    • %DIR%*.xyz loads all XYZ files in the current subfolder.
    • DEFINE_VAR with FILENAME_PIECE="PARENT_DIR" extracts the subfolder name for naming the output file.
    • Avoids recursion and uses only one DIR_LOOP_START.