import os
import shutil
if __name__ == '__main__':
#把文件夹名字先复制过去
src_folder = 'D:\\STFdata\\CIA_tiff_cropping1200-1200'
dest_folder = 'D:\\STFdata\\data\\CIA_1200'
src_folder_names = os.listdir(src_folder)
for name in src_folder_names:
dest_folder_name = os.path.join(dest_folder, name)
if not os.path.exists(dest_folder_name):
os.mkdir(dest_folder_name)
print("Folder name copied successfully!")
for i in range(1, len(src_folder_names)):
source_folder0 = os.path.join(src_folder, src_folder_names[i-1])
source_folder1 = os.path.join(src_folder, src_folder_names[i])
new_folder = os.path.join(dest_folder, src_folder_names[i])
for file_name in os.listdir(source_folder0):
if not os.path.isfile(os.path.join(source_folder0, file_name)):
continue
new_file_name = None
if 'L7' in file_name:
new_file_name = '00_landsat.tif'
elif 'MOD' in file_name:
new_file_name = '00_modis.tif'
source_file_path = os.path.join(source_folder0, file_name)
new_file_path = os.path.join(new_folder, new_file_name) if new_file_name else os.path.join(new_folder,
file_name)
shutil.copyfile(source_file_path, new_file_path)
for file_name in os.listdir(source_folder1):
if not os.path.isfile(os.path.join(source_folder1, file_name)):
continue
new_file_name = None
if 'L7' in file_name:
new_file_name = '01_landsat.tif'
elif 'MOD' in file_name:
new_file_name = '01_modis.tif'
source_file_path = os.path.join(source_folder1, file_name)
new_file_path = os.path.join(new_folder, new_file_name) if new_file_name else os.path.join(new_folder,
file_name)
shutil.copyfile(source_file_path, new_file_path)
数据集规整与制造
于 2023-04-07 21:32:46 首次发布