一、python 删除文件夹下面的所有文件

import os
CUR_PATH = r'C:\Users\xxx\Desktop\新建文件夹'
def del_file(path):
    ls = os.listdir(path)
    for i in ls:
        c_path = os.path.join(path, i)
        if os.path.isdir(c_path):
            del_file(c_path)
        else:
            os.remove(c_path)

del_file(CUR_PATH)

二、 python删除文件夹下面的所有文件夹及子文件

#!/usr/bin/env python
import os
import shutil
filelist=[]
rootdir=r"C:\Users\xxx\Desktop\新建文件夹"
filelist=os.listdir(rootdir)
for f in filelist:
  filepath = os.path.join( rootdir, f )
  if os.path.isfile(filepath):
    os.remove(filepath)
    #print filepath+" removed!"
  elif os.path.isdir(filepath):
    shutil.rmtree(filepath,True)
    #print "dir "+filepath+" removed!"