<?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: Moving files with same initial name to the match folder in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118293#M9316</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The error message indicates a copy of the file you are trying to move already exists in the location you are trying to move it to.&amp;nbsp; If you open Windows Explorer and check, are files with the same name in both locations?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the file already exists, and you don't want to overwrite it, a simple check to see if the file exists in the new location before moving/copying will prevent the error message.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Feb 2017 13:28:59 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2017-02-16T13:28:59Z</dc:date>
    <item>
      <title>Moving files with same initial name to the match folder</title>
      <link>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118285#M9308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV style="color: #222222; font-size: small;"&gt;Hi,&lt;/DIV&gt;&lt;DIV style="color: #222222; font-size: small;"&gt;I would like move automatically files witch are&amp;nbsp;scenes of Landsat 8 (each scene has 9 bands/files + MTL) inside a folder, to folders which have the same name from&amp;nbsp;initial name's files (these directories need be created).&lt;/DIV&gt;&lt;DIV style="color: #222222; font-size: small;"&gt;Each band file is Ziped separately, beyond the metadata (.txt). Next line shows a instance from the files names that already exist and a good name for a directory.&lt;/DIV&gt;&lt;DIV style="color: #222222; font-size: small;"&gt;e.g. LO82270682016229CUB00_B1.tif.zip, LO82270682016229CUB00_B2.tif.zip to directory LO82270682016229.&lt;/DIV&gt;&lt;DIV style="color: #222222; font-size: small;"&gt;I tried too a script&amp;nbsp;which needs imports the module RE, see&amp;nbsp;&lt;SPAN&gt;&lt;SPAN&gt;web page &amp;lt;&lt;A data-saferedirecturl="https://www.google.com/url?hl=pt-BR&amp;amp;q=http://stackoverflow.com/questions/25070614/python-moving-multiple-files-from-one-folder-to-the-other-based-on-text-characte&amp;amp;source=gmail&amp;amp;ust=1486828664756000&amp;amp;usg=AFQjCNFOHyIn4spqhKkJ8wpo26UkmkrB_A" href="http://stackoverflow.com/questions/25070614/python-moving-multiple-files-from-one-folder-to-the-other-based-on-text-characte" style="color: #1155cc;" target="_blank"&gt;moving multiple files&lt;/A&gt;&amp;gt;. But, unsuccessfully, the&amp;nbsp;python doesn't works - It not even shows RE module when I type import RE + enter.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV style="color: #222222; font-size: small;"&gt;The CPU's softwares are Arcmap&amp;nbsp;10.1 - Python 2.7.2&amp;nbsp;- Windows 8.&lt;/DIV&gt;&lt;DIV style="color: #222222; font-size: small;"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;DIV style="color: #222222; font-size: small;"&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; &lt;SPAN style="color: #004da8;"&gt;import&lt;/SPAN&gt; shutil&lt;/P&gt;&lt;P&gt;... &lt;SPAN style="color: #004da8;"&gt;import&lt;/SPAN&gt; os&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;... source = 'C:\Teste_Auto_CLEIA\Ima_compactadas\Landsat'&lt;/P&gt;&lt;P&gt;... dest1 = 'C:\Teste_Auto_CLEIA\Ima_compactadas\L82270682016229'&lt;/P&gt;&lt;P&gt;... dest2 = 'C:\Teste_Auto_CLEIA\Ima_compactadas\L82270692016229'&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;... files = os.listdir(source)&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;... &lt;SPAN style="color: #004da8;"&gt;for&lt;/SPAN&gt; f &lt;SPAN style="color: #004da8;"&gt;in&lt;/SPAN&gt; files:&lt;/P&gt;&lt;P&gt;... &lt;SPAN style="color: #004da8;"&gt;if&lt;/SPAN&gt; (f.startswith("LO82270682016229&lt;SPAN&gt;&lt;SPAN&gt;") &lt;SPAN style="color: #004da8;"&gt;or&lt;/SPAN&gt; f.startswith("LC82270682016229&lt;SPAN&gt;&lt;SPAN&gt;")):&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;... shutil.move(source, dest1)&amp;nbsp;&lt;SPAN style="color: #999999;"&gt;#12 line&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;... &lt;SPAN style="color: #004da8;"&gt;elif&lt;/SPAN&gt; (f.startswith("LO82270692016229&lt;SPAN&gt;&lt;SPAN&gt;") &lt;SPAN style="color: #004da8;"&gt;or&lt;/SPAN&gt; f.startswith("LC82270692016229&lt;SPAN&gt;&lt;SPAN&gt;")):&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;... shutil.move(source, dest2)&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Runtime error&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;File "&amp;lt;string&amp;gt;", line 12, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;File "C:\Python27\ArcGIS10.1\Lib\shutil.py", line 298, in move&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;copy2(src, real_dst)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;File "C:\Python27\ArcGIS10.1\Lib\shutil.py", line 127, in copy2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;copyfile(src, dst)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;File "C:\Python27\ArcGIS10.1\Lib\shutil.py", line 81, in copyfile&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;with open(src, 'rb') as fsrc:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;IOError: [Errno 2] No such file or directory: 'C:\\Teste_Auto_CLEIA\\Ima_compactadas\\Landsat'&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV style="color: #222222; font-size: small;"&gt;Thanks in advance!&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Feb 2017 16:24:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118285#M9308</guid>
      <dc:creator>BrunoDeus</dc:creator>
      <dc:date>2017-02-10T16:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Moving files with same initial name to the match folder</title>
      <link>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118286#M9309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have to specify a complete file path to be moved.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, you're saying to copy 'source' which is a folder path. &amp;nbsp;You want to include the filename which resides in that folder.&amp;nbsp;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;folder &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'C:\Test\Path\to\folder'&lt;/SPAN&gt;
destination r&lt;SPAN class="string token"&gt;'C:\Test\Path\to\destination'&lt;/SPAN&gt;
file &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'12540382834.zip'&lt;/SPAN&gt;

shuitl&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;move&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;folder&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'/'&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;file&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; destination&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:56:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118286#M9309</guid>
      <dc:creator>MitchHolley1</dc:creator>
      <dc:date>2021-12-11T06:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Moving files with same initial name to the match folder</title>
      <link>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118287#M9310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mitch,&lt;/P&gt;&lt;P&gt;I'm grateful for your help. I tried do it, but the same line (now is 14) is with trouble.&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&amp;gt;&amp;gt;&amp;gt; import shutil&lt;BR /&gt;... import os&lt;BR /&gt;... &lt;BR /&gt;... source = r'C:\Test\Landsat'&lt;SPAN style="color: #999999;"&gt;# I shorted it to easier - The folder with all files.&lt;/SPAN&gt;&lt;BR /&gt;... dest1 = r'C:\Test\L8227068'&lt;SPAN style="color: #999999;"&gt;# I shorted it to easier&lt;/SPAN&gt;&lt;BR /&gt;... dest2 = r'C:\Test\L8227069'&lt;SPAN style="color: #999999;"&gt;# I shorted it to easier&lt;/SPAN&gt;&lt;BR /&gt;... file1 = 'LO82270682016229*'&lt;SPAN style="color: #999999;"&gt;# I changed it to work with all bands&lt;/SPAN&gt;&lt;BR /&gt;... file2 = 'LO82270692016229*'&lt;SPAN style="color: #999999;"&gt;# I changed it to work with all bands&lt;/SPAN&gt;&lt;BR /&gt;... &lt;BR /&gt;... files = os.listdir(source)&lt;BR /&gt;... &lt;BR /&gt;... for f in files:&lt;BR /&gt;... if (f.startswith("LO8227068") or f.startswith("LC8227068")):&lt;BR /&gt;... shutil.move(source+'/'+file1, dest1)&lt;SPAN style="color: #999999;"&gt;#14 line&lt;/SPAN&gt;&lt;BR /&gt;... elif (f.startswith("LO8227069") or f.startswith("LC8227069")):&lt;BR /&gt;... shutil.move(source+'/'+file2, dest2)&lt;BR /&gt;... &lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;Runtime error &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt; File "&amp;lt;string&amp;gt;", line 14, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt; File "C:\Python27\ArcGIS10.4\Lib\shutil.py", line 302, in move&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt; copy2(src, real_dst)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt; File "C:\Python27\ArcGIS10.4\Lib\shutil.py", line 130, in copy2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt; copyfile(src, dst)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt; File "C:\Python27\ArcGIS10.4\Lib\shutil.py", line 82, in copyfile&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt; with open(src, 'rb') as fsrc:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;IOError: [Errno 22] invalid mode ('rb') or filename: 'C:\\Test\\Landsat/LO82270682016229*'&lt;/SPAN&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Feb 2017 00:20:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118287#M9310</guid>
      <dc:creator>BrunoDeus</dc:creator>
      <dc:date>2017-02-11T00:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Moving files with same initial name to the match folder</title>
      <link>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118288#M9311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are creating invalid file names, i.e.,&amp;nbsp;&lt;SPAN style="color: #ff0000;"&gt;'C:\\Test\\Landsat/LO82270682016229*'&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; .&amp;nbsp; I recommend using &lt;A href="https://docs.python.org/2/library/os.path.html"&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;os.path&lt;/SPAN&gt;&lt;/A&gt; when building file system path names.&amp;nbsp; That said, I believe it is your use of asterisks/wildcards that is causing the error here.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Feb 2017 15:23:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118288#M9311</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2017-02-11T15:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: Moving files with same initial name to the match folder</title>
      <link>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118289#M9312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I aready replaced those lines for:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro" style="background: none #f6f6f6; border-left: 2px solid #cccccc; margin: 10px 0px; padding: 10px 20px;"&gt;&lt;P&gt;&lt;/P&gt;... file1 = 'LO82270682016229CUB00_B1.tif.zip'# I changed it to work with 1 band&lt;BR /&gt;... file2 = 'LO82270692016229CUB00_B1.tif.zip'# I changed it to work with 1 band&lt;/BLOCKQUOTE&gt;&lt;P&gt;But, the script stops after remove the "file1" to a file without extension with the same name from the folder that It should go. i.e. the scripts needs be shifted to create folders from the last piece of directory's destine.&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro" style="background: none #f6f6f6; border-left: 2px solid #cccccc; margin: 10px 0px; padding: 10px 20px;"&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Runtime error &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;File "&amp;lt;string&amp;gt;", line 14, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;File "C:\Python27\ArcGIS10.4\Lib\shutil.py", line 302, in move&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;copy2(src, real_dst)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;File "C:\Python27\ArcGIS10.4\Lib\shutil.py", line 130, in copy2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;copyfile(src, dst)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;File "C:\Python27\ArcGIS10.4\Lib\shutil.py", line 82, in copyfile&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;with open(src, 'rb') as fsrc:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;IOError: [Errno 2] No such file or directory: 'C:\\Test\\Landsat/LO82270682016229CUB00_B1.tif.zip'&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I'm looking for the python page from your link and think and trying the best way. Also, I should try do a script without the name from each file&amp;nbsp;to avoid update (re-script) it every time that I will use it.&lt;/P&gt;&lt;P&gt;I pretend put the best try here, when I find the best function. I'm considering too others python's&amp;nbsp;pages.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Feb 2017 22:49:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118289#M9312</guid>
      <dc:creator>BrunoDeus1</dc:creator>
      <dc:date>2017-02-12T22:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: Moving files with same initial name to the match folder</title>
      <link>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118290#M9313</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The last 3 lines of the error message are telling you the &lt;SPAN style="font-family: courier new,courier,monospace;"&gt;copyfile&lt;/SPAN&gt; function, which is being called by the &lt;SPAN style="font-family: courier new,courier,monospace;"&gt;move&lt;/SPAN&gt; function, cannot find the file &lt;SPAN style="font-family: courier new,courier,monospace;"&gt;'C:\\Test\\Landsat/LO82270682016229CUB00_B1.tif.zip'&lt;/SPAN&gt; to open and read.&amp;nbsp; I don't have anything else to offer, the Python interpreter isn't finding the file using the path you are passing it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Feb 2017 16:14:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118290#M9313</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2017-02-13T16:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: Moving files with same initial name to the match folder</title>
      <link>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118291#M9314</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I ran the script and looks that&amp;nbsp;later him remove the file, It doesn' find the file at the original path. I checked the file's name and the basename at statement, both of them match.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Feb 2017 01:40:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118291#M9314</guid>
      <dc:creator>BrunoDeus1</dc:creator>
      <dc:date>2017-02-14T01:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Moving files with same initial name to the match folder</title>
      <link>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118292#M9315</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My best shot was do 1 script to create the folders and run it first. I avoid script it with the second one for precaution, I think that is possible the script&amp;nbsp;moves the band's file to a directory and later, that this directory be replaced for a new empty folder.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In the first script, I just wanna create path with the same basename onetime. Is there &lt;/SPAN&gt;&lt;SPAN&gt;any&lt;/SPAN&gt;&lt;SPAN&gt;one who knows how to do it?&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; import fnmatch &lt;SPAN style="color: #999999;"&gt;#This script create the folders&lt;/SPAN&gt;&lt;BR /&gt;... &lt;BR /&gt;... source = r'C:\Test\Landsat'&lt;BR /&gt;... &lt;BR /&gt;... for file in os.listdir(source):&lt;BR /&gt;... if fnmatch.fnmatch(file, 'L?8*'):&lt;BR /&gt;... arcpy.CreateFolder_management(test, file[:16])&lt;BR /&gt;... print file[:16]&lt;SPAN style="color: #999999;"&gt;#This line is just to know which folders have been created&lt;/SPAN&gt;&lt;BR /&gt;... &lt;BR /&gt;&lt;SPAN style="color: #999999;"&gt;LO82270682016229&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #999999;"&gt;LO82270682016229&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #999999;"&gt;LO82270692016229&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #999999;"&gt;LO82270692016229&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And at the last script, it fails after move the first file&amp;nbsp;to the right path.&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; import shutil&lt;BR /&gt;... import os, fnmatch &lt;SPAN style="color: #999999;"&gt;#put fnmatch&lt;/SPAN&gt;&lt;BR /&gt;... &lt;BR /&gt;... source = r'C:\Test\Landsat'&lt;BR /&gt;... dest1 = r'C:\Test\LO82270682016229'&lt;SPAN style="color: #999999;"&gt;#put the same name from the folders created one step before&lt;/SPAN&gt;&lt;BR /&gt;... dest2 = r'C:\Test\LO82270692016229'&lt;SPAN style="color: #999999;"&gt;#put the same name from the folders created one step before&lt;/SPAN&gt;&lt;BR /&gt;... file1 = 'LO82270682016229CUB00_B1.tif.zip'&lt;SPAN style="color: #999999;"&gt;# I changed it to work with 1 band&lt;/SPAN&gt;&lt;BR /&gt;... file2 = 'LO82270692016229CUB00_B1.tif.zip'&lt;SPAN style="color: #999999;"&gt;# I changed it to work with 1 band&lt;/SPAN&gt;&lt;BR /&gt;... &lt;BR /&gt;... files = os.listdir(source)&lt;BR /&gt;... &lt;BR /&gt;... for f in files:&lt;SPAN style="color: #999999;"&gt;#12 line - This line is OK&lt;/SPAN&gt; &lt;BR /&gt;... if (f.startswith("LO8227068") or f.startswith("LC8227068")):&lt;BR /&gt;... shutil.move(source+'/'+file1, dest1)&lt;BR /&gt;... elif (f.startswith("LO8227069") or f.startswith("LC8227069")):&lt;BR /&gt;... shutil.move(source+'/'+file2, dest2)&lt;BR /&gt;... &lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;Runtime error &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt; File "&amp;lt;string&amp;gt;", line 14, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt; File "C:\Python27\ArcGIS10.4\Lib\shutil.py", line 292, in move&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt; raise Error, "Destination path '%s' already exists" % real_dst&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;Error: Destination path 'C:\Test\LO82270682016229\LO82270682016229CUB00_B1.tif.zip' already exists&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*I did a script that joined both of them, and It created the folders like the first. But it failed so soon it moved one file, by the same way that these two scripts above did. You can see the message error below:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Runtime error &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt; File "&amp;lt;string&amp;gt;", line 17, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt; File "C:\Python27\ArcGIS10.4\Lib\shutil.py", line 292, in move&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt; raise Error, "Destination path '%s' already exists" % real_dst&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;Error: Destination path 'C:\Test\LO82270682016229\LO82270682016229CUB00_B1.tif.zip' already exists&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, if has someone to help, I will be thankful!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Feb 2017 05:00:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118292#M9315</guid>
      <dc:creator>BrunoDeus1</dc:creator>
      <dc:date>2017-02-16T05:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Moving files with same initial name to the match folder</title>
      <link>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118293#M9316</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The error message indicates a copy of the file you are trying to move already exists in the location you are trying to move it to.&amp;nbsp; If you open Windows Explorer and check, are files with the same name in both locations?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the file already exists, and you don't want to overwrite it, a simple check to see if the file exists in the new location before moving/copying will prevent the error message.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Feb 2017 13:28:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118293#M9316</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2017-02-16T13:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: Moving files with same initial name to the match folder</title>
      <link>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118294#M9317</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Before script runs, it's all right. Is the script that creates the folder and moves the file. But, the script looks the path with the file that himself moved and see an error.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Feb 2017 14:36:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-files-with-same-initial-name-to-the-match/m-p/118294#M9317</guid>
      <dc:creator>BrunoDeus1</dc:creator>
      <dc:date>2017-02-16T14:36:07Z</dc:date>
    </item>
  </channel>
</rss>

