可以使用 osshutil 模块来实现这个功能,具体实现如下:

import os
import shutil

# 获取当前目录下的所有.cif文件
cif_files = [f for f in os.listdir('.') if f.endswith('.cif')]

# 遍历每个.cif文件
for cif_file in cif_files:
    # 获取文件名(不包含后缀)
    file_name = os.path.splitext(cif_file)[0]
    # 创建文件夹
    os.makedirs(file_name, exist_ok=True)
    # 移动文件到对应文件夹
    shutil.move(cif_file, file_name)

以上代码会在当前目录下创建与每个.cif文件同名的文件夹,并将对应文件移动到该文件夹中。如果文件夹已经存在,则不需要再创建。

Python脚本:将当前目录下.cif文件移动到同名文件夹

原文地址: https://www.cveoy.top/t/topic/npk0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录