LoginSignup
16
11

More than 5 years have passed since last update.

[python]隠しファイルをリストから除く

Last updated at Posted at 2018-05-19

os.listdir() を使うと、引数で指定したpath内のファイル一覧を出力できます。しかし隠しファイル(.DS_store等)も一緒に表示されてしまいます。
この隠しファイルを除去したいときは以下のようにしています。

from os import listdir
fltr_list = [filename for filename in listdir(path) if not filename.startswith('.')]

このfltr_listの中に隠しファイルを除いたリストが格納されます。

16
11
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
16
11