<?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 Python Scrypt to step back a directory in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-scrypt-to-step-back-a-directory/m-p/634329#M49417</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would like to step back a directory in python without having to prompt the user to do it in my script. For example the user selects a dataset here C:\Projects\test\database.mdb\dataset to run a process on. I then want the database that the dataset is in to be compacted without prompting the user for the database as well. Basically I want to know what the python version of cd.. is&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Sep 2011 21:08:10 GMT</pubDate>
    <dc:creator>philiptivel</dc:creator>
    <dc:date>2011-09-14T21:08:10Z</dc:date>
    <item>
      <title>Python Scrypt to step back a directory</title>
      <link>https://community.esri.com/t5/python-questions/python-scrypt-to-step-back-a-directory/m-p/634329#M49417</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would like to step back a directory in python without having to prompt the user to do it in my script. For example the user selects a dataset here C:\Projects\test\database.mdb\dataset to run a process on. I then want the database that the dataset is in to be compacted without prompting the user for the database as well. Basically I want to know what the python version of cd.. is&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Sep 2011 21:08:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-scrypt-to-step-back-a-directory/m-p/634329#M49417</guid>
      <dc:creator>philiptivel</dc:creator>
      <dc:date>2011-09-14T21:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: Python Scrypt to step back a directory</title>
      <link>https://community.esri.com/t5/python-questions/python-scrypt-to-step-back-a-directory/m-p/634330#M49418</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi there,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are a couple of ways to do this, though Python's built-in way would be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;os.path.dirname(path_to_dataset)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os
pathX = r'C:/Hello/HelloWorld'
print os.path.dirname(pathX)&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Result: &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;C:/Hello&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;which returns the parent directory of the file or folder under consideration. So, if you feed it a file, it will give the directory the file is in. If you give it a folder, it will return the folder hosting it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:59:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-scrypt-to-step-back-a-directory/m-p/634330#M49418</guid>
      <dc:creator>MarcNakleh</dc:creator>
      <dc:date>2021-12-12T02:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: Python Scrypt to step back a directory</title>
      <link>https://community.esri.com/t5/python-questions/python-scrypt-to-step-back-a-directory/m-p/634331#M49419</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That worked great, thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Sep 2011 02:45:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-scrypt-to-step-back-a-directory/m-p/634331#M49419</guid>
      <dc:creator>philiptivel</dc:creator>
      <dc:date>2011-09-15T02:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: Python Scrypt to step back a directory</title>
      <link>https://community.esri.com/t5/python-questions/python-scrypt-to-step-back-a-directory/m-p/634332#M49420</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can also do what you were suggesting in your original post (change directories "back one") by using os.chdir():&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print "Current: "+os.getcwd()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt; C:/jobs/Alpine&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;os.chdir('..')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print "Back one dir: "+os.getcwd()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt; C:/jobs&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Sep 2011 12:20:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-scrypt-to-step-back-a-directory/m-p/634332#M49420</guid>
      <dc:creator>RDHarles</dc:creator>
      <dc:date>2011-09-15T12:20:15Z</dc:date>
    </item>
  </channel>
</rss>

