python 复制文件
#!/usr/bin/env python # -*- coding: utf-8 -*- import os source_root = 'D:\source' test_root = 'D:\target' files_list = 'files.txt' def main(): with open(files_list,'r') as f: for l in f: tmp = l.strip().replace('/commbook/trunk/commbook','') tmp = tmp.replace('/','\\') s = source_root + tmp t = test_root + tmp mkdir(t) print 'copy "'+ s +'" "'+ t +'"' os.system('copy "'+ s +'" "'+ t +'"') return 0 def mkdir(filename): segs = filename.split('\\') count = len(segs) for i in range(2,count): p = '\\'.join(segs[:i]) if(not os.path.exists(p)): os.system('mkdir "'+ p +'"') if __name__ == '__main__': main()