Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,868 questions

51,791 answers

573 users

How to search and print all filenames matching a specified pattern in PHP

2 Answers

0 votes
/*
array glob( string $pattern [, int $flags = 0 ] )
*/  
  
echo "<pre>";
print_r(glob("e:/*.txt"));
echo "</pre>";


/*
run:
  
Array
(
    [0] => e:/3LData.txt
    [2] => e:/backup.txt
    [4] => e:/data.txt
    [14] => e:/numbers.txt
    [15] => e:/temp.txt
    [18] => e:/test.txt
)
*/

 



answered Dec 16, 2015 by avibootz
edited Dec 16, 2015 by avibootz
0 votes
/*
array glob( string $pattern [, int $flags = 0 ] )
*/  
  
foreach (glob("e:/*.txt") as $filename) 
    echo "$filename size " . number_format(filesize($filename)) . "<br />";


/*
run:
  
e:/3LData.txt size 296,595
e:/data.txt size 20
e:/temp.txt size 310
e:/test.txt size 47

*/

 



answered Dec 16, 2015 by avibootz

Related questions

1 answer 146 views
2 answers 224 views
224 views asked Jun 3, 2021 by avibootz
2 answers 110 views
1 answer 117 views
...