1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ディレクトリ内の指定した語,拡張子を含むファイル名を検索する

Last updated at Posted at 2016-01-13

指定したディレクトリ内にあるファイルで,指定した単語と拡張子を含むものを検索する.
関数呼び出しの際に,拡張子の部分にドット(.)を含むのを忘れないように.

def check_file(path='./',file_name='',ext=''):
    import os
    import os.path

    _ch = os.listdir(path)
    ch_e = []

    for _ in _ch:
        _root, _ext = os.path.splitext(_)
        if file_name in _root and _ext == ext:
            ch_e.append(_)
        else:
            pass

    return ch_e

ch = check_file(path,'name','.txt')
1
1
1

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?