mshd.net
当前位置:首页 >> python 如何将一个文件夹里面的文件重新命名并复制... >>

python 如何将一个文件夹里面的文件重新命名并复制...

#!/usr/bin/env python# -*- coding:utf-8 -*-import osrootdirA = os.getcwd()+os.sep+'A'+os.seprootdirB = os.getcwd()+os.sep+'B'+os.sepcmd = 'copy %s%s %s%s'for parent,dirnames,filenames in os.walk(rootdirA): #遍历a文件夹所有文件 ...

#批量修改,将lig/ligand里面所有abc.mol改成dock.mol,请指教import osimport reorglist = os.listdir('./lig/ligand')for orgname in orglist: filename = orgname.replace('adc.mol','dock.mol) os.rename("%s"%orgname,"%s"%filename) print...

import osimport shutilpathA = 'G:/A'pathB = 'G:/B'for f in os.listdir(pathA): if os.path.isfile(pathA + os.path.sep + f): os.rename(pathA+ os.path.sep + f, pathA + os.path.sep + f.replace('rank_', '').replace('_m1_1.', '.')) sh...

import shutilimport ospath1 = r''path2 = r''path1_ls = os.listdir(path1)path2_ls = []for i in range(len(path1_ls)): path1_ls[i] = os.path.join(path1, path1_ls[i]) path2_la.append(os.path.join(path2,paht1_ls[i].replace("_out",""...

import reimport osdef get_file_list(folder): file_list = []; for root, dirs, files in os.walk(folder): for f in files: path=root+os.path.sep+f file_list.append(path) return file_listdef get_re_file_list(file_list,re_rule): file...

# 123456/add_dirname.py (python3.6)import osfs = [i for i in os.listdir() if not i.endswith('.py')]dirname = os.path.basename(os.getcwd())[os.rename(i, f'{dirname}{i}') for i in fs]

import shutilimport ospath1 = r''path2 = r''path1_ls = os.listdir(path1)path2_ls = []for i in range(len(path1_ls)): path1_ls[i] = os.path.join(path1, path1_ls[i]) path2_la.append(os.path.join(path2,paht1_ls[i].replace("_%d_%d"%...

import osimport shutildef wenjian(path): if os.path.isfile(path): shutil.copy(path,'c:\\new_dir') if os.path.isdir(path): lists = os.listdir(path) for i in lists: wenjian(i) for i in os.walk('c:\\1'): wenjian(i)建议你把检索到的...

import os,shutilfor filename in open(result.out): shutil.copy(os.path.join(r'文件夹A',filename+'.mol'),r'文件夹B')

import osimport shutilroot = 'F:\\python2'for rt, dirs, files in os.walk(root): for f in files: fn = os.path.join(rt, f) nfn = fn.replace('.txt', '.py'). if src in fn and fn != nfn: shutil.move(fn, nfn)

网站首页 | 网站地图
All rights reserved Powered by www.mshd.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com