<?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 Multiple workspaces in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/multiple-workspaces/m-p/670395#M51934</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I am trying to list data from one workspace, check if it exists in another, and if not, copy it to the new database (because in the middle of copying it can error out on a file and I don't want to wait for it to overwrite everything I have already copied over). I have tried many different ways but whenever I define 2 workspaces in the same code it errors that the file already exists (ignores overwriteOutput = true) or says the file can't be copied because it is not supported/does not exist. Will copy fine when 1 workspace is defined but I have to wait for it to copy everything all over again. Hope this makes sense.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;works:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os, traceback
arcpy.env.overwriteOutput = True
arcpy.env.workspace = in_ws
cpfiles = arcpy.ListFiles()
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for c in cpfiles:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in_path, in_name = os.path.split(c)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Copying " + in_name + " to " + out_path + in_name)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Copy_management(c, out_path + in_name) 
&amp;nbsp;&amp;nbsp;&amp;nbsp; del c
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; traceback.print_exc()
&amp;nbsp;&amp;nbsp;&amp;nbsp; raw_input("Cannot copy" + c + ", copy it over manually and run script again")
finally:
&amp;nbsp;&amp;nbsp;&amp;nbsp; raw_input("Finished!")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;does not work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os, traceback
arcpy.env.overwriteOutput = True

def find_all_files(workspace):
&amp;nbsp;&amp;nbsp;&amp;nbsp; prev_workspace = arcpy.env.workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; files = arcpy.ListFiles()
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = prev_workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; return files
cpfiles = find_all_files(in_ws)
exfiles = find_all_files(out_ws)
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for c in cpfiles:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in_path, in_name = os.path.split(c)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not c in exfiles:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.AddMessage(out_path + in_name) #get correct message, lists file not yet copied over
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Copying " + in_name + " to " + out_path + in_name)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Copy_management(c, out_path + in_name) # error does not exist/is not supported
&amp;nbsp;&amp;nbsp;&amp;nbsp; del c 
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; traceback.print_exc()
&amp;nbsp;&amp;nbsp;&amp;nbsp; raw_input("Cannot copy " + c + ", copy it over manually and run script again")
finally:
&amp;nbsp;&amp;nbsp;&amp;nbsp; raw_input("Finished!")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 04:17:57 GMT</pubDate>
    <dc:creator>AmyKlug</dc:creator>
    <dc:date>2021-12-12T04:17:57Z</dc:date>
    <item>
      <title>Multiple workspaces</title>
      <link>https://community.esri.com/t5/python-questions/multiple-workspaces/m-p/670395#M51934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I am trying to list data from one workspace, check if it exists in another, and if not, copy it to the new database (because in the middle of copying it can error out on a file and I don't want to wait for it to overwrite everything I have already copied over). I have tried many different ways but whenever I define 2 workspaces in the same code it errors that the file already exists (ignores overwriteOutput = true) or says the file can't be copied because it is not supported/does not exist. Will copy fine when 1 workspace is defined but I have to wait for it to copy everything all over again. Hope this makes sense.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;works:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os, traceback
arcpy.env.overwriteOutput = True
arcpy.env.workspace = in_ws
cpfiles = arcpy.ListFiles()
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for c in cpfiles:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in_path, in_name = os.path.split(c)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Copying " + in_name + " to " + out_path + in_name)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Copy_management(c, out_path + in_name) 
&amp;nbsp;&amp;nbsp;&amp;nbsp; del c
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; traceback.print_exc()
&amp;nbsp;&amp;nbsp;&amp;nbsp; raw_input("Cannot copy" + c + ", copy it over manually and run script again")
finally:
&amp;nbsp;&amp;nbsp;&amp;nbsp; raw_input("Finished!")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;does not work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os, traceback
arcpy.env.overwriteOutput = True

def find_all_files(workspace):
&amp;nbsp;&amp;nbsp;&amp;nbsp; prev_workspace = arcpy.env.workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; files = arcpy.ListFiles()
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = prev_workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; return files
cpfiles = find_all_files(in_ws)
exfiles = find_all_files(out_ws)
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for c in cpfiles:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in_path, in_name = os.path.split(c)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not c in exfiles:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.AddMessage(out_path + in_name) #get correct message, lists file not yet copied over
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Copying " + in_name + " to " + out_path + in_name)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Copy_management(c, out_path + in_name) # error does not exist/is not supported
&amp;nbsp;&amp;nbsp;&amp;nbsp; del c 
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; traceback.print_exc()
&amp;nbsp;&amp;nbsp;&amp;nbsp; raw_input("Cannot copy " + c + ", copy it over manually and run script again")
finally:
&amp;nbsp;&amp;nbsp;&amp;nbsp; raw_input("Finished!")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:17:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multiple-workspaces/m-p/670395#M51934</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2021-12-12T04:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple workspaces</title>
      <link>https://community.esri.com/t5/python-questions/multiple-workspaces/m-p/670396#M51935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You only need to set the workspace when you use the listfiles. For the rest just combine the in_ws and out_ws to obtain a reference to the source and destination, like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os

def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; import traceback
&amp;nbsp;&amp;nbsp;&amp;nbsp; in_ws = r"C:\Forum\CopyFiles\InFolder"
&amp;nbsp;&amp;nbsp;&amp;nbsp; out_ws = r"C:\Forum\CopyFiles\OutFolder"

&amp;nbsp;&amp;nbsp;&amp;nbsp; cpfiles = find_all_files(in_ws)
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for c in cpfiles:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; destination = os.path.join(out_ws, c)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not arcpy.Exists(destination):
&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; arcpy.AddMessage("Copying {0} to {1}".format(c, out_ws))
&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; arcpy.Copy_management(os.path.join(in_ws, c), destination)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del c
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; traceback.print_exc()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Cannot copy {0}, copy it over manually and run script again".format(c))
&amp;nbsp;&amp;nbsp;&amp;nbsp; finally:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Finished!")

def find_all_files(workspace):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; files = arcpy.ListFiles()
&amp;nbsp;&amp;nbsp;&amp;nbsp; return files

if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:18:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multiple-workspaces/m-p/670396#M51935</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-12T04:18:00Z</dc:date>
    </item>
  </channel>
</rss>

