按步骤,仅作记录,比较乱,以下代码为linux环境运行。
第一步:创建文件夹准备存放对应模态数据
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import shutil
import re
def extract_file(path_name):
# make new directory
# directory_name = ['t1','t2','rest','dti','tof','aaheadscouts']
directory_name = ['t1','rest','dti']
for name in directory_name:
try:
os.makedirs(path_name + '/' + name)
# os.rmdir(path_name + '/' + name)
except:
continue
# get current files
# directory = os.listdir(path_name)
# for i in directory:
# dir_files = os.listdir(i)
#old_dir_name = 'XXX/XXX'
dir_name = '/XXX/done'
new_name = '/XXX/second'
for i in os.listdir(dir_name):
# 这里创建文件夹只能循环一次
#os.makedirs(dir_name + r'//' + i)
new_dir_name = os.path.join(new_name + '/' + i)
#os.makedirs(new_dir_name)
extract_file(new_dir_name)
# extract_file('C://AA/...')
第二步:把T1、DTI、REST分别拷贝到对应文件夹
# -*- coding: utf-8 -*-
# encoding:utf-8
import os
import re
import string
import shutil
dir_name = '/xxx/done'
target_dir = '/xxx/second'
for i in os.listdir(dir_name):
cur_path = os.path.join(dir_name + '/' + i)
if os.path.isdir(cur_path):
# print(cur_path)
for j in os.listdir(cur_path):
cur_son_path = os.path.join(cur_path + '/' + j)
# print(type(j))
# print(cur_son_oath)
# 判断是哪个模态
if 'co' in j:
# shutil.copy(cur_son_path,target_dir + '/' + i + '/'+ 't1')
t1_name = j[2:-4]
# print(j)
# print(t1_name)
for k in os.listdir(cur_path):
if t1_name in k:
cur_son_son_path = os.path.join(cur_path + '/' + k)
print "Now it is copying "+ k + " t1 files"
shutil.move(cur_son_son_path,target_dir + '/' + i + '/'+ 't1')
if 'bvec' in j:
dti_name = j[:-5]
# print(dti_name)
for l in os.listdir(cur_path):
if dti_name in l:
cur_son_son_path = os.path.join(cur_path + '/' + l)
print "Now it is copying "+ l + " dti files"
shutil.move(cur_son_son_path,target_dir + '/' + i + '/'+ 'dti')
第三步:为协作人员创建文件夹准备拷贝对应模态文件,比如这里协作人员需要的是DTI模态
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import shutil
import re
def extract_file(path_name):
# make new directory
# directory_name = ['t1','t2','rest','dti','tof','aaheadscouts']
directory_name = ['dti']
for name in directory_name:
try:
os.makedirs(path_name + '/' + name)
# os.rmdir(path_name + '/' + name)
except:
continue
# get current files
# directory = os.listdir(path_name)
# for i in directory:
# dir_files = os.listdir(i)
dir_name = '/XXX/done'
new_name = '/XXX/xxx'
for i in os.listdir(dir_name):
# 这里只能循环一次
#os.makedirs(dir_name + r'//' + i)
new_dir_name = os.path.join(new_name + '/' + i)
#os.makedirs(new_dir_name)
extract_file(new_dir_name)
# extract_file('C://AA/...')
第四步:把对应模态文件拷贝给协作人员
# -*- coding: utf-8 -*-
# encoding:utf-8
import os
import re
import shutil
dir_name = '/brain/xxx'
target_dir = '/brain/Tom/xxx'
for i in os.listdir(dir_name):
cur_path = os.path.join(dir_name + '/' + i)
if os.path.isdir(cur_path):
# print(cur_path)
for j in os.listdir(cur_path):
if j == 'dti':
cur_son_path = os.path.join(cur_path + '/' + j)
for k in os.listdir(cur_son_path):
#k = str(k)
# print(type(j))
# print(cur_son_oath)
print "Now it is copying "+ k + " dti files"
shutil.copy(cur_son_path + '/' + k,target_dir + '/' + i + '/'+ 'dti')
20190123
网友评论