How to use glob() to find files recursively?

前端 未结 28 1780
天涯浪人
天涯浪人 2020-11-21 22:54

This is what I have:

glob(os.path.join(\'src\',\'*.c\'))

but I want to search the subfolders of src. Something like this would work:

<
28条回答
  •  孤独总比滥情好
    2020-11-21 23:17

    Recently I had to recover my pictures with the extension .jpg. I ran photorec and recovered 4579 directories 2.2 million files within, having tremendous variety of extensions.With the script below I was able to select 50133 files havin .jpg extension within minutes:

    #!/usr/binenv python2.7
    
    import glob
    import shutil
    import os
    
    src_dir = "/home/mustafa/Masaüstü/yedek"
    dst_dir = "/home/mustafa/Genel/media"
    for mediafile in glob.iglob(os.path.join(src_dir, "*", "*.jpg")): #"*" is for subdirectory
        shutil.copy(mediafile, dst_dir)
    

提交回复
热议问题