<?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: Get parent folder of GDB as a string. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/get-parent-folder-of-gdb-as-a-string/m-p/1209893#M65492</link>
    <description>&lt;LI-CODE lang="python"&gt;from pathlib import Path

def get_folder(dataset):
    parent = Path(dataset).parent
    if "." in parent.name: # .gdb, .sde
        return str(parent.parent)
    return str(parent)&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 06 Sep 2022 14:51:09 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-09-06T14:51:09Z</dc:date>
    <item>
      <title>Get parent folder of GDB as a string.</title>
      <link>https://community.esri.com/t5/python-questions/get-parent-folder-of-gdb-as-a-string/m-p/1209873#M65490</link>
      <description>&lt;P&gt;I just need a bit of code that will look at the input feature class and return a value which is the parent OS folder that the GDB or SDE or other database resides in.&lt;/P&gt;&lt;P&gt;So far i have the following, but it returns the full path up to the feature dataset. I would like the code to return the folder path up until a geodatabase, And if the data is a shapefile, to just choose the parent folder.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os
from arcpy import metadata as md
dataset = arcpy.GetParameterAsText(0)

workspace = os.path.dirname(dataset)
walk = arcpy.da.Walk(workspace)
for dirpath, dirnames, filenames in walk:
    arcpy.AddMessage(dirpath)&lt;/LI-CODE&gt;&lt;P&gt;Greatly appreciated,&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 14:36:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-parent-folder-of-gdb-as-a-string/m-p/1209873#M65490</guid>
      <dc:creator>David_Brooks</dc:creator>
      <dc:date>2022-09-06T14:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: Get parent folder of GDB as a string.</title>
      <link>https://community.esri.com/t5/python-questions/get-parent-folder-of-gdb-as-a-string/m-p/1209893#M65492</link>
      <description>&lt;LI-CODE lang="python"&gt;from pathlib import Path

def get_folder(dataset):
    parent = Path(dataset).parent
    if "." in parent.name: # .gdb, .sde
        return str(parent.parent)
    return str(parent)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 06 Sep 2022 14:51:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-parent-folder-of-gdb-as-a-string/m-p/1209893#M65492</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-09-06T14:51:09Z</dc:date>
    </item>
  </channel>
</rss>

