美文网首页
Python批量删除全文件夹下的部分指定文件名的文件

Python批量删除全文件夹下的部分指定文件名的文件

作者: TomHu_blog001 | 来源:发表于2019-08-21 05:00 被阅读0次

    Python批量删除全文件夹下的部分指定文件名的文件

    “”"

    Python批量删除指定文件夹下的指定文件名的文件

    “”"

    import os ##首先导入os模块,进行文件的查找,修改,删除等操作一般都要事先导入os模块

    def file_name(file_dir):

    list = []

    for root, dirs, files in os.walk(file_dir):

    for file in files:

    list.append(file)

    return list

    list = file_name(r’F:\testp\1’)#找出要删除文件的列名

    print(list)

    for i in range(len(list)):

    os.remove(r’F:\testp\2\’ + list[i])

    相关文章

      网友评论

          本文标题:Python批量删除全文件夹下的部分指定文件名的文件

          本文链接:https://www.haomeiwen.com/subject/vhzlsctx.html