<?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: Using Python to copy more than one raster at a time in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-python-to-copy-more-than-one-raster-at-a/m-p/10310#M901</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You want to use ListRasters() and a for loop. &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000001s000000" rel="nofollow noopener noreferrer" target="_blank"&gt;An example from ESRI&lt;/A&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy 
from arcpy import env&amp;nbsp; 

# Set the current workspace&amp;nbsp; 
env.workspace = "C:/Data/DEMS" 
 
# Get a list of ESRI GRIDs from the workspace and print 
rasterList = arcpy.ListRasters("*", "GRID") 
for raster in rasterList:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; print raster # replace this with your copy code&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The ()'s and *'s in your file names might be a problem, though. Also, a few thousand will take a long time, and might overwhelm your system. You might also want to look at the Raster to Other Format tool.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 20:26:02 GMT</pubDate>
    <dc:creator>Zeke</dc:creator>
    <dc:date>2021-12-10T20:26:02Z</dc:date>
    <item>
      <title>Using Python to copy more than one raster at a time</title>
      <link>https://community.esri.com/t5/python-questions/using-python-to-copy-more-than-one-raster-at-a/m-p/10309#M900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;sorry if I am cross posting but I am relatively new to the ArcGIS world. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I think my problem will be easily solvable by somebody with a little knowledge of ArcGIS/Programming.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Basically, I need to transform a few thousands of .tiff raster into .bil and I was trying to run a simple Python command along the line of:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CopyRaster_management("e:/Pyton/prova/tif/(africa_arc.1983*)","e:/Pyton/prova/bil/(1983*.bil)")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;because all the input file starts with the same name and I don't particularly care about the output name as long as the file are distinguishable from one another. There is obviously a lot wrong with my command line, the only small experience I have in programming is in STATA which works very differently (I am an economist and there is one person in my whole department knowing what ArcGIS is, let alone Python). &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If this is as easy as I imagine having a little knowledge on the language and anybody feels like giving me an answer this will save me a lot of time!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Giovanni&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Mar 2014 13:33:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-to-copy-more-than-one-raster-at-a/m-p/10309#M900</guid>
      <dc:creator>GiovanniOcchiali</dc:creator>
      <dc:date>2014-03-27T13:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python to copy more than one raster at a time</title>
      <link>https://community.esri.com/t5/python-questions/using-python-to-copy-more-than-one-raster-at-a/m-p/10310#M901</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You want to use ListRasters() and a for loop. &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000001s000000" rel="nofollow noopener noreferrer" target="_blank"&gt;An example from ESRI&lt;/A&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy 
from arcpy import env&amp;nbsp; 

# Set the current workspace&amp;nbsp; 
env.workspace = "C:/Data/DEMS" 
 
# Get a list of ESRI GRIDs from the workspace and print 
rasterList = arcpy.ListRasters("*", "GRID") 
for raster in rasterList:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; print raster # replace this with your copy code&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The ()'s and *'s in your file names might be a problem, though. Also, a few thousand will take a long time, and might overwhelm your system. You might also want to look at the Raster to Other Format tool.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:26:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-to-copy-more-than-one-raster-at-a/m-p/10310#M901</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2021-12-10T20:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python to copy more than one raster at a time</title>
      <link>https://community.esri.com/t5/python-questions/using-python-to-copy-more-than-one-raster-at-a/m-p/10311#M902</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you very much,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;that hasn't work but it was useful in pointing me towards the right direction, but unfortunately I'm still not there.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When trying with arcpy.ListRasters I could not seen anything happening (not even the print line was actually returning the raster list) so I have tried with arcpy.ListDataset specifying the "Raster" wildcard&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
arcpy.env.workspace = "E:/Pyton/Prova/Tif"
datasetList = arcpy.ListDatasets("a*", "Raster")
for dataset in datasetList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyRaster_management(datasetList,"e:/Pyton/prova/bil/")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but the return code I was then having is a general "Runtime error &amp;lt;type 'exceptions.RuntimeError'&amp;gt;: Object: Error in executing tool" which I guess might depend on the fact that I haven't specified the name of the file to be saved.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;After a further look around Help and Forum I am now trying something along the line of:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
from arcpy import env
InputLoc = raw_input("E:/Pyton/Prova/tif/")
arcpy.env.workspace = InputLoc
targetDatasetList=arcpy.ListDatasets("a*", "Raster")
outLoc = raw_input("e:/Pyton/prova/bil/")
outDirectory = outLoc
for dataset in targetDatasetList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; tif = str(dataset)
&amp;nbsp;&amp;nbsp;&amp;nbsp; outRast = tif[:-4] + "_jul.bil"
&amp;nbsp;&amp;nbsp;&amp;nbsp; outDataset = outDirectory + "//" + outRast
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyRaster_management(tif,outDataset)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;which though returns "Runtime error &amp;lt;type 'exceptions.EOFError'&amp;gt;: EOF when reading a line"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Any idea of what might be wrong?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Again, thank you very much in advance to whoever is going to dedicate me sometime. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Giovanni&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:26:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-to-copy-more-than-one-raster-at-a/m-p/10311#M902</guid>
      <dc:creator>GiovanniOcchiali</dc:creator>
      <dc:date>2021-12-10T20:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python to copy more than one raster at a time</title>
      <link>https://community.esri.com/t5/python-questions/using-python-to-copy-more-than-one-raster-at-a/m-p/10312#M903</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In your first example, you should pass CopyRaster dataset, rather than datasetList. Also not a good idea to use the word dataset as a variable name, since that has a specific meaning in ArcGIS and may be a reserved word in arcpy as well. You could just use d instead. Then, you're correct that you need to give an actual path &amp;amp; raster name. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In your ListRasters call, "Raster" is an incorrect specification. In your case you want "TIF". I've also never seen a wildcard listed with a letter in List type functions, but don't know that it's incorrect. In any case, it would only get tifs starting with 'a'.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's your first code corrected:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy&amp;nbsp; arcpy.env.workspace = "E:/Pyton/Prova/Tif"&amp;nbsp; datasetList = arcpy.ListDatasets("*", "TIF")&amp;nbsp; for d in datasetList:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyRaster_management(d,"e:/Pyton/prova/bil/new_rastername.bil") &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN style="font-family:arial;"&gt;&lt;FONT face="verdana"&gt;&lt;SPAN style="font-size:3;"&gt;&lt;SPAN style="font-size:2;"&gt;See &lt;A class="jive-link-external-small" href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Copy_Raster/001700000094000000/" rel="nofollow" target="_blank"&gt;here&amp;nbsp; &lt;/A&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-size:2;"&gt;As for your second example, I didn't go through it closely, but generally,&lt;BR /&gt;it's not a good idea to end paths with a slash. Also, you don't want two &lt;BR /&gt;slashes if you're using '/'. You'd only use two with '\' because '\' is &lt;BR /&gt;an escape character, or if you were starting a UNC path.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Mar 2014 18:43:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-to-copy-more-than-one-raster-at-a/m-p/10312#M903</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-03-27T18:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python to copy more than one raster at a time</title>
      <link>https://community.esri.com/t5/python-questions/using-python-to-copy-more-than-one-raster-at-a/m-p/10313#M904</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I did now get to a working code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy 
arcpy.env.workspace = "E:/Pyton/Prova/Tif" 
outLoc = ("e:/Pyton/prova/bil")
outDirectory = outLoc
datasetList = arcpy.ListDatasets("*", "Raster") 
for d in datasetList:
 tif = str(d)
 outRast = tif + "_jul.bil"
 outD = outDirectory + "/" + outRast
 arcpy.CopyRaster_management(tif,outD) &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Apparently though TIF is a specification only for RasterList (which for some reason appears not to work for me) but not for DatasetList (while the a* depended on the fact that all my .tif start with a &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; )&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:26:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-to-copy-more-than-one-raster-at-a/m-p/10313#M904</guid>
      <dc:creator>GiovanniOcchiali</dc:creator>
      <dc:date>2021-12-10T20:26:08Z</dc:date>
    </item>
  </channel>
</rss>

