peter_anderson Posted February 7, 2010 Share Posted February 7, 2010 Hello, I am trying to load the name of all .txt files within the directory, excluding one. I cannot think of the best way to approach it (if any)? Can anyone help? Thanks Quote Link to comment Share on other sites More sharing options...
xjake88x Posted February 7, 2010 Share Posted February 7, 2010 <?php //Open directory $dir = dir("my/directory"); //List files in directory while (($file = $dir->read()) !== false){ //Make sure it's a .txt file if(strlen($file) < 5 || substr($file, -4) != '.txt') continue; echo "filename: " . $file . "<br />"; } $dir->close(); ?> Quote Link to comment Share on other sites More sharing options...
$Three3 Posted February 7, 2010 Share Posted February 7, 2010 Hello, I am trying to load the name of all .txt files within the directory, excluding one. I cannot think of the best way to approach it (if any)? Can anyone help? Thanks You most likely use a for loop or a foreach loop depending if you're dealing with an array or not. You might also want to heck out the substr() function, the is_file() function, is_dir() function, scandir() function. That should get you started. Quote Link to comment Share on other sites More sharing options...
peter_anderson Posted February 7, 2010 Author Share Posted February 7, 2010 <?php //Open directory $dir = dir("my/directory"); //List files in directory while (($file = $dir->read()) !== false){ //Make sure it's a .txt file if(strlen($file) < 5 || substr($file, -4) != '.txt') continue; echo "filename: " . $file . "<br />"; } $dir->close(); ?> Thank you {resolved} Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.