Imaulle Posted January 11, 2011 Share Posted January 11, 2011 Hello, I'm trying to make a little piece of code that will search for all files (including subdirectories) ending with .txt and set them to 777 foreach (glob("*.txt") as $file) { system("chmod 777 '$file'"); } Am I on the right path? thanks Quote Link to comment Share on other sites More sharing options...
nderevj Posted January 11, 2011 Share Posted January 11, 2011 Close, however that will only get you the files in the current directory (not in any sub-directories). Try this: <?php $directory = 'sample'; // Replace with your starting directory $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); while($it->valid()) { if(strtolower(substr($it->getFilename(), -4)) == '.txt') { var_dump($it->key()); // Not really needed, just used for debugging chmod($it->key(), 0777); } $it->next(); } Quote Link to comment Share on other sites More sharing options...
Imaulle Posted January 11, 2011 Author Share Posted January 11, 2011 that worked perfectly! thank you! 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.