brunodeus

Moving files with same initial name to the match folder

Discussion created by brunodeus on Feb 10, 2017
Latest reply on Feb 16, 2017 by BrunodeDeus
Hi,
I would like move automatically files witch are scenes of Landsat 8 (each scene has 9 bands/files + MTL) inside a folder, to folders which have the same name from initial name's files (these directories need be created).
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.
e.g. LO82270682016229CUB00_B1.tif.zip, LO82270682016229CUB00_B2.tif.zip to directory LO82270682016229.
I tried too a script which needs imports the module RE, see web page <moving multiple files>. But, unsuccessfully, the python doesn't works - It not even shows RE module when I type import RE + enter.
The CPU's softwares are Arcmap 10.1 - Python 2.7.2 - Windows 8.
 

>>> import shutil

... import os

...

... source = 'C:\Teste_Auto_CLEIA\Ima_compactadas\Landsat'

... dest1 = 'C:\Teste_Auto_CLEIA\Ima_compactadas\L82270682016229'

... dest2 = 'C:\Teste_Auto_CLEIA\Ima_compactadas\L82270692016229'

...

... files = os.listdir(source)

...

... for f in files:

... if (f.startswith("LO82270682016229") or f.startswith("LC82270682016229")):

... shutil.move(source, dest1) #12 line

... elif (f.startswith("LO82270692016229") or f.startswith("LC82270692016229")):

... shutil.move(source, dest2)

...

Runtime error

Traceback (most recent call last):

File "<string>", line 12, in <module>

File "C:\Python27\ArcGIS10.1\Lib\shutil.py", line 298, in move

copy2(src, real_dst)

File "C:\Python27\ArcGIS10.1\Lib\shutil.py", line 127, in copy2

copyfile(src, dst)

File "C:\Python27\ArcGIS10.1\Lib\shutil.py", line 81, in copyfile

with open(src, 'rb') as fsrc:

IOError: [Errno 2] No such file or directory: 'C:\\Teste_Auto_CLEIA\\Ima_compactadas\\Landsat'

Thanks in advance!

Outcomes