python批量更改gldas文件nc4格式名称(原格式带“:”)无法处理
python批量更改gldas文件nc4格式名称,原格式带“:”无法处理
·
import os
import shutil
# 源文件夹路径
source_folder = r'G:\xxxx'#需要转换的gldas文件夹
# 目标文件夹路径
destination_folder = r'G:\XXX'#新的gldas文件夹
# 遍历文件夹下的所有文件
for filename in os.listdir(source_folder):
if filename.endswith('.nc4'): # 只处理后缀为.nc4的文件
new_filename = filename.replace('ː', '_') # 替换冒号为下划线#这里的“:”只能copy这个
source_file = os.path.join(source_folder, filename) # 原文件路径
destination_file = os.path.join(destination_folder, new_filename) # 目标文件路径
shutil.move(source_file, destination_file) # 移动文件到目标文件夹
更多推荐
所有评论(0)