Deleting files by type in Python on Windows

前端 未结 3 1493
时光说笑
时光说笑 2021-01-18 02:40

I know how to delete single files, however I am lost in my implementation of how to delete all files in a directory of one type.

Say the directory is \\myfolder

3条回答
  •  我在风中等你
    2021-01-18 03:11

    Use the glob module:

    import os
    from glob import glob
    
    for f in glob ('myfolder/*.config'):
       os.unlink (f)
    

提交回复
热议问题