Select to view content in your preferred language

Combining Fields for a file name in python

245
3
Jump to solution
07-21-2025 12:07 PM
RobertBorchert
Honored Contributor

I am exporting attachments from an Table with Attachments.   I want to combine 2 fields from the base table  for the folder name.  

This is what I have.  I have named the fields FileName1 and FileName2.  I just cannot figure out how to combine them 

Issues is the name of the origin Table

# -*- coding: utf-8 -*-
"""
Generated by ArcGIS ModelBuilder on : 2025-07-21 13:23:03
"""
import arcpy

def Model(): # Model

# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = False

arcpy.ImportToolbox(r"c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Data Management Tools.tbx")
Issues = "Issues"
NRPExportTest = "\\\\gisfs01\\GIS_Cache$\\GISData\\RobertTemp\\NRPExportTest"
FileName1 = "ISSUENAME_W"
FileName2 = "WORKGROUP"
output_filename = f"{FileName1}"
# Process: Export Attachments (Export Attachments) (management)
Output_Directories = arcpy.management.ExportAttachments(in_dataset=Issues, out_location=NRPExportTest, subdirectory_field= output_filename)[0]

if __name__ == '__main__':
# Global Environment settings
with arcpy.EnvManager(scratchWorkspace="\\\\gisfs01\\GIS_Cache$\\PortalServices\\PGIS\\FieldMarkups\\FieldMarkups.gdb", workspace="\\\\gisfs01\\GIS_Cache$\\PortalServices\\PGIS\\FieldMarkups\\FieldMarkups.gdb"):
Model()

 

0 Kudos
1 Solution

Accepted Solutions
CodyPatterson
MVP Regular Contributor

Hey @RobertBorchert 

You're pretty close from what I can see! Do something like this here:

def Model():  # Model
    # To allow overwriting outputs change overwriteOutput option to True.
    arcpy.env.overwriteOutput = False

    arcpy.ImportToolbox(r"c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Data Management Tools.tbx")
    Issues = "Issues"
    NRPExportTest = r"\\gisfs01\GIS_Cache$\GISData\RobertTemp\NRPExportTest"
    FileName1 = "ISSUENAME_W"
    FileName2 = "WORKGROUP"
    # Create the folder here:
    output_filename = f"{FileName1} + '/' + {FileName2}"

    # Process: Export Attachments (Export Attachments) (management)
    Output_Directories = arcpy.management.ExportAttachments(
        in_dataset=Issues,
        out_location=NRPExportTest,
        subdirectory_field=output_filename
    )[0]

if __name__ == '__main__':
    # Global Environment settings
    with arcpy.EnvManager(
        scratchWorkspace=r"\\gisfs01\GIS_Cache$\PortalServices\PGIS\FieldMarkups\FieldMarkups.gdb",
        workspace=r"\\gisfs01\GIS_Cache$\PortalServices\PGIS\FieldMarkups\FieldMarkups.gdb"
    ):
        Model()

You should be able to create a function string to add the two filenames together!

Cody

View solution in original post

0 Kudos
3 Replies
RobertBorchert
Honored Contributor

Or better yet for my purposes allow me to create a subfolder under ISSUENAME_W  using WORKGROUP

0 Kudos
CodyPatterson
MVP Regular Contributor

Hey @RobertBorchert 

You're pretty close from what I can see! Do something like this here:

def Model():  # Model
    # To allow overwriting outputs change overwriteOutput option to True.
    arcpy.env.overwriteOutput = False

    arcpy.ImportToolbox(r"c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Data Management Tools.tbx")
    Issues = "Issues"
    NRPExportTest = r"\\gisfs01\GIS_Cache$\GISData\RobertTemp\NRPExportTest"
    FileName1 = "ISSUENAME_W"
    FileName2 = "WORKGROUP"
    # Create the folder here:
    output_filename = f"{FileName1} + '/' + {FileName2}"

    # Process: Export Attachments (Export Attachments) (management)
    Output_Directories = arcpy.management.ExportAttachments(
        in_dataset=Issues,
        out_location=NRPExportTest,
        subdirectory_field=output_filename
    )[0]

if __name__ == '__main__':
    # Global Environment settings
    with arcpy.EnvManager(
        scratchWorkspace=r"\\gisfs01\GIS_Cache$\PortalServices\PGIS\FieldMarkups\FieldMarkups.gdb",
        workspace=r"\\gisfs01\GIS_Cache$\PortalServices\PGIS\FieldMarkups\FieldMarkups.gdb"
    ):
        Model()

You should be able to create a function string to add the two filenames together!

Cody

0 Kudos
RobertBorchert
Honored Contributor

Thanks I will give that a shot

0 Kudos