python整理文件

# -*- coding: cp936 -*-
import os,os.path,sys,shutil
rpath = raw_input("输入你要整理的路径:")
folder = raw_input("输入你要存放的路径:")
if not os.path.isdir(folder):
    os.mkdir(folder,777)
    
os.chdir(rpath)
for root,dirs,files in os.walk(rpath):
    for m_f in files:
        if os.path.splitext(m_f)[1] == ".pdf":
            print m_f
            if not os.path.isdir(folder+os.sep+"pdf"):
                os.mkdir(folder+os.sep+"pdf")
            try:
                shutil.move(root+os.sep+m_f,folder+os.sep+"pdf")
            except:
                continue
        elif os.path.splitext(m_f)[1] == ".chm" or os.path.splitext(m_f)[1] == ".chw":
            print m_f
            if not os.path.isdir(folder+os.sep+"chm"):
                os.mkdir(folder+os.sep+"chm")
            try:
                shutil.move(root+os.sep+m_f,folder+os.sep+"chm")
            except:
                continue

你可能感兴趣的:(python,F#,OS)