1

I use this method

array_map('unlink', glob("data/words/*.*"));

To delete all files Including all .txt extension and It works well

But when there is a file named ..txt is not deleted

Skora
  • 107
  • 11

1 Answers1

1

Please note that glob('*') ignores all 'hidden' files by default. This means it does not return files that start with a dot (e.g. .file).

If you want to match those files too, you can use "{,.}*" as the pattern with the GLOB_BRACE flag.

<?php
// Search for all files that match .* or *
$files = glob('{,.}*', GLOB_BRACE);
?>

Specifically in your case, this should work.

array_map('unlink', glob("data/words/{,.}*",GLOB_BRACE));

Look at: http://php.net/manual/en/function.glob.php#68869

A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103