Display all files in directory beginning with A

Reply

Join Date: Jul 2009
Posts: 16
Reputation: peck3277 is an unknown quantity at this point 
Solved Threads: 0
peck3277 peck3277 is offline Offline
Newbie Poster

Display all files in directory beginning with A

 
0
  #1
34 Days Ago
Hi all,

I've tried searching both here and google for help on this one. I'm not quite sure what to call it basically I have a directory with different files all .txt. I want to display only the ones beginning with letter A. How do I modify my below code to do this?

  1. <?php
  2. if ($handle = opendir('poems/')) {
  3. while (false !== ($file = readdir($handle))) {
  4. if ($file != "." && $file != "..") {
  5. echo "$file\n <br />";
  6. }
  7. }
  8. closedir($handle);
  9. }
  10. ?>

I know I need to use something like A* but I don't even know what to call it to search for it?

Thanks!
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey
 
0
  #2
34 Days Ago
Originally Posted by peck3277 View Post
Hi all,

I've tried searching both here and google for help on this one. I'm not quite sure what to call it basically I have a directory with different files all .txt. I want to display only the ones beginning with letter A. How do I modify my below code to do this?

  1. <?php
  2. if ($handle = opendir('poems/')) {
  3. while (false !== ($file = readdir($handle))) {
  4. if ($file != "." && $file != "..") {
  5. echo "$file\n <br />";
  6. }
  7. }
  8. closedir($handle);
  9. }
  10. ?>

I know I need to use something like A* but I don't even know what to call it to search for it?

Thanks!

  1. <?php
  2. if ($handle = opendir('poems/')) {
  3. while (false !== ($file = readdir($handle))) {
  4. if ($file != "." && $file != ".." && $file[0] == 'A') {
  5. echo "$file\n <br />";
  6. }
  7. }
  8. closedir($handle);
  9. }
Last edited by ShawnCplus; 34 Days Ago at 11:24 am.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 16
Reputation: peck3277 is an unknown quantity at this point 
Solved Threads: 0
peck3277 peck3277 is offline Offline
Newbie Poster
 
0
  #3
34 Days Ago
Thanks for the quick reply ShawnCplus. It spares me an awful lot of pain and hair ripping! Thank you so much!
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey
 
0
  #4
34 Days Ago
Originally Posted by peck3277 View Post
Thanks for the quick reply ShawnCplus. It spares me an awful lot of pain and hair ripping! Thank you so much!
As a short explanation strings are arrays of characters so if you want to get the 3rd letter in a string just do $string[2] (counting begines at 0)
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC