Omzy Posted January 11, 2010 Share Posted January 11, 2010 Just having a little trouble creating the code to check if a directory is empty, if not then get the list of files in that directory excluding hidden/system files. Anyone able to advise? Quote Link to comment Share on other sites More sharing options...
Omzy Posted January 11, 2010 Author Share Posted January 11, 2010 Anyone able to help? Quote Link to comment Share on other sites More sharing options...
trq Posted January 11, 2010 Share Posted January 11, 2010 $contents = glob('/directory/*'); if ($contents) { foreach ($contents as $file) { echo $file . "\n"; } } Quote Link to comment Share on other sites More sharing options...
Omzy Posted January 11, 2010 Author Share Posted January 11, 2010 Cheers thorpe, that's perfect. Just one slight issue in that it returns true if there are hidden files in the folder. How can I exclude hidden files? Quote Link to comment Share on other sites More sharing options...
trq Posted January 11, 2010 Share Posted January 11, 2010 It shouldn't. What exactly do you mean by hidden files? Your not using windows are you? Quote Link to comment Share on other sites More sharing options...
Omzy Posted January 11, 2010 Author Share Posted January 11, 2010 lol yes i'm developing this site on apache localhost on windows. i take it'll work just fine on linux server. Quote Link to comment Share on other sites More sharing options...
trq Posted January 11, 2010 Share Posted January 11, 2010 Yeah, windows hidden files work differently and aren't recognized as being hidden simply by name. I'm not sure how you would do it on windows to be honest. stat might help you out, though you will need check each file within the loop. Quote Link to comment Share on other sites More sharing options...
Omzy Posted January 11, 2010 Author Share Posted January 11, 2010 OK cool. How about if I limit it to check for certain extensions? The only ones I need to check for are .doc, .docx and .pdf Quote Link to comment Share on other sites More sharing options...
calmchess Posted January 11, 2010 Share Posted January 11, 2010 i have bat file that does what you want all you have to do is call it via exec command yo ntrested? Quote Link to comment Share on other sites More sharing options...
Omzy Posted January 11, 2010 Author Share Posted January 11, 2010 Bump for thorpe Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted January 11, 2010 Share Posted January 11, 2010 you can use the GLOB_BRACE flag to specify that you want to use the brace syntax in the glob pattern. you can use that to specify different extensions. for example $glob = glob("director/*.{pdf,doc,docx}", GLOB_BRACE); check out the manual entry for more information 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.