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 moves the band's file to a directory and later, that this directory be replaced for a new empty folder.
In the first script, I just wanna create path with the same basename onetime. Is there anyone who knows how to do it?
>>> import fnmatch #This script create the folders
...
... source = r'C:\Test\Landsat'
...
... for file in os.listdir(source):
... if fnmatch.fnmatch(file, 'L?8*'):
... arcpy.CreateFolder_management(test, file[:16])
... print file[:16]#This line is just to know which folders have been created
...
LO82270682016229
LO82270682016229
LO82270692016229
LO82270692016229
And at the last script, it fails after move the first file to the right path.
>>> import shutil
... import os, fnmatch #put fnmatch
...
... source = r'C:\Test\Landsat'
... dest1 = r'C:\Test\LO82270682016229'#put the same name from the folders created one step before
... dest2 = r'C:\Test\LO82270692016229'#put the same name from the folders created one step before
... file1 = 'LO82270682016229CUB00_B1.tif.zip'# I changed it to work with 1 band
... file2 = 'LO82270692016229CUB00_B1.tif.zip'# I changed it to work with 1 band
...
... files = os.listdir(source)
...
... for f in files:#12 line - This line is OK
... if (f.startswith("LO8227068") or f.startswith("LC8227068")):
... shutil.move(source+'/'+file1, dest1)
... elif (f.startswith("LO8227069") or f.startswith("LC8227069")):
... shutil.move(source+'/'+file2, dest2)
...
Runtime error
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "C:\Python27\ArcGIS10.4\Lib\shutil.py", line 292, in move
raise Error, "Destination path '%s' already exists" % real_dst
Error: Destination path 'C:\Test\LO82270682016229\LO82270682016229CUB00_B1.tif.zip' already exists
*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:
Runtime error
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "C:\Python27\ArcGIS10.4\Lib\shutil.py", line 292, in move
raise Error, "Destination path '%s' already exists" % real_dst
Error: Destination path 'C:\Test\LO82270682016229\LO82270682016229CUB00_B1.tif.zip' already exists
So, if has someone to help, I will be thankful!