<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python dataitem.export Issues (FGDB Naming) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-dataitem-export-issues-fgdb-naming/m-p/1131563#M63432</link>
    <description>&lt;P&gt;I don't think you can rename the gdb using a parameter in the export function. However, you could rename the File Geodatabase after you extracted the zip file using &lt;A href="https://docs.python.org/3/library/os.html#os.rename" target="_self"&gt;rename&lt;/A&gt;, also from os.&amp;nbsp;&lt;/P&gt;&lt;P&gt;By the way: the export function actually returns the new item so there's no need to search for this after exporting if you catch the new item from the export function.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jan 2022 13:19:08 GMT</pubDate>
    <dc:creator>AdminGIS2</dc:creator>
    <dc:date>2022-01-07T13:19:08Z</dc:date>
    <item>
      <title>Python dataitem.export Issues (FGDB Naming)</title>
      <link>https://community.esri.com/t5/python-questions/python-dataitem-export-issues-fgdb-naming/m-p/1128156#M63358</link>
      <description>&lt;P&gt;I am building a Python script for a client who wants a bunch of hosted feature services exported to file geodatabases. The script I've written works just fine. Each hosted feature service is exported to a GDB then downloaded to a location of my choosing.&lt;/P&gt;&lt;P&gt;The issue is that each unzipped GDB has a seemingly random name. For example:&lt;/P&gt;&lt;P&gt;'Test_Layer_1.zip' once unzipped turns into '_ags_dataD621677BB64F4D2D98CD0D1B1CF805BD.gdb'.&lt;/P&gt;&lt;P&gt;Is there a way to set the name of the GDB as a parameter?&lt;/P&gt;&lt;P&gt;Here is what I've worked out so far...&lt;/P&gt;&lt;LI-CODE lang="python"&gt;## Import modules
import os
import datetime
from arcgis.gis import GIS
import zipfile

# Create destination folder 
today = datetime.datetime.now()
path = 'C:/workspace/pythontest' + today.strftime('%m%d%Y')
os.mkdir(path)
dest = path
extension = ".zip"

# Define variables for GIS
PortalUrl = 'https://redacted.redacted.local/portal'
PortalUserName = 'username'
PortalPassword = 'password'
gis = GIS(PortalUrl, PortalUserName, PortalPassword)

# Define input layers
# itemid1 = 'c9325f2f3d7b430b93047230bbe004ac' = 'Test_Layer_1'
# itemid2 = 'edfe40f03dee40839a92ee2bd695cf62' = 'Test_Layer_2'
itemid1 = 'c9325f2f3d7b430b93047230bbe004ac'
itemid2 = 'edfe40f03dee40839a92ee2bd695cf62'

# Export Test_Layer_1
dataitem1 = gis.content.get(itemid1)
dataitem1.export('Test_Layer_1', 'File Geodatabase', parameters=None, wait=True)
myexport1 = gis.content.search('Test_Layer_1', item_type='File Geodatabase')
fgdb1 = gis.content.get(myexport1[0].itemid)
fgdb1.download(save_path=dest, file_name='Test_Layer_1' + ".zip")
fgdb1.delete()

# Export Test_Layer_2
dataitem2 = gis.content.get(itemid2)
dataitem2.export('Test_Layer_2', 'File Geodatabase', parameters=None, wait=True)
myexport2 = gis.content.search('Test_Layer_2', item_type='File Geodatabase')
fgdb2 = gis.content.get(myexport2[0].itemid)
fgdb2.download(save_path=dest, file_name='Test_Layer_2' + ".zip")
fgdb2.delete()

# Unzip ZIP files then delete the ZIP files
os.chdir(dest) # change directory from working dir to dir with files
for item in os.listdir(dest): # loop through items in dir
    if item.endswith(extension): # check for ".zip" extension
        file_name = os.path.abspath(item) # get full path of files
        zip_ref = zipfile.ZipFile(file_name) # create zipfile object
        zip_ref.extractall(dest) # extract file to dir
        zip_ref.close() # close file
        os.remove(file_name) # delete zipped file&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 21:19:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-dataitem-export-issues-fgdb-naming/m-p/1128156#M63358</guid>
      <dc:creator>babarsac</dc:creator>
      <dc:date>2021-12-21T21:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: Python dataitem.export Issues (FGDB Naming)</title>
      <link>https://community.esri.com/t5/python-questions/python-dataitem-export-issues-fgdb-naming/m-p/1131563#M63432</link>
      <description>&lt;P&gt;I don't think you can rename the gdb using a parameter in the export function. However, you could rename the File Geodatabase after you extracted the zip file using &lt;A href="https://docs.python.org/3/library/os.html#os.rename" target="_self"&gt;rename&lt;/A&gt;, also from os.&amp;nbsp;&lt;/P&gt;&lt;P&gt;By the way: the export function actually returns the new item so there's no need to search for this after exporting if you catch the new item from the export function.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 13:19:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-dataitem-export-issues-fgdb-naming/m-p/1131563#M63432</guid>
      <dc:creator>AdminGIS2</dc:creator>
      <dc:date>2022-01-07T13:19:08Z</dc:date>
    </item>
  </channel>
</rss>

