[After GF6-WFV data preprocessing is completed - python batch processing tool - move and store files in folders according to suffixes]

GF6-WFV data preprocessing

Data_Rad_Fla_Rpc_bm-XX-JG-sub.dat, through the suffix name, realize the python program to move and store the files in folders according to the suffix

problems encountered

insert image description here

problems encountered

insert image description here

desired outcome

insert image description here

insert image description here

The above content is implemented in Python - the specific code is as follows:

insert image description here

import os
import shutil

def romve_file(input,output,name):
    output_path = os.path.join(output, name.split(".")[0])
    if not os.path.exists(output_path):
        os.mkdir(output_path)
    for file in os.listdir(input):
        if file.endswith(name):
            output_path_abs = os.path.join(output_path, file)
            input_path_abs=os.path.join(input,file)
            shutil.move(input_path_abs,output_path_abs)

        # 主程序说明:将文件夹内的文件,根据相关的规则进行移动,完成数据归类处理
if __name__ == '__main__':
    # 读取文件名命名规则
    name_all=["2BDA-JG.dat","BR-JG.dat",'NDCI-JG.dat']
    # 设置输出和输入路径
    input_path = r"E:\4研究区——20230317备份\B.GT-GF6-WFV+19-22年\5.TEST20230317补\3-二次裁剪"
    output_path = r"E:\4研究区——20230317备份\B.GT-GF6-WFV+19-22年\5.TEST20230317补\4.分模型存储"
    # 设置输出文件夹的名称和规则
    for name in name_all:
        romve_file(input_path,output_path,name)


Python is really easy to use, the overall code is made with the help of classmates, the processing time has been shortened a lot, python —— YYDS, python is awesome!

Guess you like

Origin blog.csdn.net/qq_36253366/article/details/129963064