這個程式碼是為了 Hack.lu CTF 2017-Flatscience-writeup 補上的,傳送門#
# !/usr/bin/python
# - * - coding:utf-8 - * -
'''
@author: soapffz
@fucntion: 遞歸尋找多層目錄中指定類型檔案
@time: 2019-01-06
'''
import os
import shutil
src_dir = r"C:\Users\soapffz\Desktop\dir" # 注意複製目錄路徑的時候最前面可能有個看不見的字元
to_dir = os.path.join(os.path.expanduser("~") + "\\" +
"Desktop" + "\\" + "to_dir") # 生成的資料夾放在了桌面
os.mkdir(to_dir)
def search_file(path):
for item in os.listdir(path):
subFile = os.path.join(path + "\\" + item)
if os.path.isdir(subFile):
search_file(subFile)
else:
if os.path.splitext(subFile)[1] == ".pdf":
shutil.copy(subFile, to_dir)
if __name__ == "__main__":
search_file(src_dir)