<?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 Arcpy changing current working directory in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-changing-current-working-directory/m-p/330451#M25694</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I can't seem to understand the following behaviour:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
mxd = ur'G:\MapImageCreator\ImageTaker.mxd'

print os.getcwd()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # C:\Documents and Settings\dabkowsk\Desktop (where I run the script from)
mxd = arcpy.mapping.MapDocument(mxd)
print os.getcwd()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # G:\MapImageCreator
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why does creating a MapDocument object change my working directory? This way I can't use any relative path in my entire script. For example, if I describe an output file as just 'abcdefg.txt', it gets created in the mxd's directory, not in the one I run the script from.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 May 2013 13:07:07 GMT</pubDate>
    <dc:creator>GrzegorzDabkowski</dc:creator>
    <dc:date>2013-05-14T13:07:07Z</dc:date>
    <item>
      <title>Arcpy changing current working directory</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-changing-current-working-directory/m-p/330451#M25694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I can't seem to understand the following behaviour:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
mxd = ur'G:\MapImageCreator\ImageTaker.mxd'

print os.getcwd()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # C:\Documents and Settings\dabkowsk\Desktop (where I run the script from)
mxd = arcpy.mapping.MapDocument(mxd)
print os.getcwd()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # G:\MapImageCreator
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why does creating a MapDocument object change my working directory? This way I can't use any relative path in my entire script. For example, if I describe an output file as just 'abcdefg.txt', it gets created in the mxd's directory, not in the one I run the script from.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2013 13:07:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-changing-current-working-directory/m-p/330451#M25694</guid>
      <dc:creator>GrzegorzDabkowski</dc:creator>
      <dc:date>2013-05-14T13:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy changing current working directory</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-changing-current-working-directory/m-p/330452#M25695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure why that would happen, I guess its just defaulting to somewhere as the workspace has not been set.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You set the workspace with the following code&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.env.workspace = r"C:\temp"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2013 13:33:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-changing-current-working-directory/m-p/330452#M25695</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2013-05-14T13:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy changing current working directory</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-changing-current-working-directory/m-p/330453#M25696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Setting arcpy.env.workspace will not affect my text file creation, will it? Would it affect the other step, creation of a MapDocument? Would it prevent the current working directory from changing? I'll certainly try. But even if it's defaulting, why is that affecting the global cwd, not the arcpy-specific path? I checked the state of arcpy.env.workspace too, it remains None throughout the execution of the code above.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2013 16:03:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-changing-current-working-directory/m-p/330453#M25696</guid>
      <dc:creator>GrzegorzDabkowski</dc:creator>
      <dc:date>2013-05-14T16:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy changing current working directory</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-changing-current-working-directory/m-p/330454#M25697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I added a line setting arcpy.env.workspace, but that didn't change anything.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 May 2013 05:48:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-changing-current-working-directory/m-p/330454#M25697</guid>
      <dc:creator>GrzegorzDabkowski</dc:creator>
      <dc:date>2013-05-15T05:48:28Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy changing current working directory</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-changing-current-working-directory/m-p/330455#M25698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To wrap this up, &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//005700000009000000.htm"&gt;documentation &lt;/A&gt;&lt;SPAN&gt; says as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You cannot type relative paths (using the dot and double-dot notation) in any ArcGIS application. Nor can you use relative paths in Python scripts.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I decided to explicitly transform all input relative paths to absolute ones at the beginning of the script, before any arcpy method uses them. It's certainly not convenient not to be able to use relative paths, especially if some interactive use is envisaged, but it seems that's just a limitation of the environment.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 May 2013 06:34:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-changing-current-working-directory/m-p/330455#M25698</guid>
      <dc:creator>GrzegorzDabkowski</dc:creator>
      <dc:date>2013-05-20T06:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy changing current working directory</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-changing-current-working-directory/m-p/330456#M25699</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;relying on environment settings that can change unexpectedly is not a safe practice.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you can get the path parameters set as you need at the outset, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;you can then capture the paths to variables and use the variables to give explicit paths.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That way, Arc and the system can switch between 'current' directories all day, but you have already &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;captured the locations for later use&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;scriptHome = os.getcwd()&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 May 2013 11:34:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-changing-current-working-directory/m-p/330456#M25699</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2013-05-20T11:34:54Z</dc:date>
    </item>
  </channel>
</rss>

