7
2

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.

glob('*')だと隠しファイルは検索対象にならない

Last updated at Posted at 2013-08-25

glob関数は、指定したパターンに一致するファイルを配列として取得する便利な関数ですが、何も考えず

$list = glob('/tmp/*');

などとやってしまうと、ドットで始まるファイル(隠しファイル)はヒットしません。そのような隠しファイルを検索したい場合はGLOB_BRACEオプションを指定して隠しファイルもヒットするようにパターンを指定しましょう。

$list = glob('/tmp/{*,.*}',GLOB_BRACE);

「"." や ".." はいらん」という場合はさらにパターンを指定して...

$list = glob('/tmp/{*,.[!.]*,..?*}',GLOB_BRACE);

としましょう。

なお、DirectoryIteratorおよびopendirで取得する場合は何も指定しなくても隠しファイルを検索できるようです。

7
2
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
7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?