话不多说,先上代码:
pwd = os.getcwd() # 获得当前工作目录 filePath = 'C:\Users\Administrator\Desktop\Course comments\Number\\' + category # 得到该分类的所有课程 file_course_list = os.listdir(filePath) # print len(file_course_list) # 去掉.csv后缀 courses_name = [file_course.split('.')[0] for file_course in file_course_list] for course_name in courses_name: if course_name not in clean_course: clean_course.append(course_name)
#删除指定路径的csv文件
name = os.path.join(course_name+'.csv') os.remove(os.path.join(filePath,name)) print name