LoginSignup
1
0

More than 3 years have passed since last update.

Pythonでフォルダ配下のファイルをファイル名で検索してみた

Posted at

ソースコード

import subprocess
import glob
import pathlib

def find(url, fil):
        share = pathlib.WindowsPath(url)
        try:
                if share.exists():
                        print(url)
                        for x in share.glob(fil):
                                print(str(x).replace(url, ''))
                return True
        except:
                import traceback
                traceback.print_exc()
                input("Press Enter to continue...")
                return False

def doFunc():
        print('検索キーワードを入力して下さい')
        word = input()

        if word:
                print('キーワード 『'+word+'』で検索中です。')
                url = r'D:\\対象フォルダ'
                fil = '**/[!(~$)]*' + word + '*.*'
                return find(url,fil)
        else:
                return True

        input("検索が完了しました。\nEnterキーを押すと処理を終了します。")


while doFunc():
        print('処理を継続します!\n'+"-"*100)
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0