文件批量删除

文件批量删除


import os 


def del_file(absPath,fileName,do_del=False):
    del_file_start_end(absPath=absPath,fileName=fileName,startswith="csdn",endswith=".html",do_del=do_del)
    del_file_start_end(absPath=absPath,fileName=fileName,startswith="zhiPin_page",endswith=".html",do_del=do_del)
    del_file_start_end(absPath=absPath,fileName=fileName,startswith="boss_detail",endswith=".html",do_del=do_del)


def del_file_start_end(absPath,fileName,startswith,endswith,do_del=False):
    
    isPair=fileName.startswith(startswith) and  fileName.endswith(endswith)
    if not isPair:
        return
    print("absPath del",absPath)
    if do_del:
        os.remove(absPath)


def del_path_files(dir_name=rf'H:\movedAli',do_del=False):
    pass
    for fileName in os.listdir(dir_name):
        absPath=os.path.join(dir_name,fileName)
        del_file(absPath=absPath,fileName=fileName,do_del=do_del)

del_path_files(dir_name=rf'H:\movedAli',do_del=True)

你可能感兴趣的:(python,开发语言)