So you can do this using scandir
like you mentioned and yes filesystem can be pretty slow, you can add a check in so you do not do it to files you have already processed
<?php
$files = scandir('./');
foreach ($files as $file) {
// check here so you don't have to do every file again
if (substr(sprintf('%o', fileperms($file)), -4) === "0660") {
echo "skipping " . $file;
continue;
}
$extension = pathinfo($file)['extension'];
if ($extension === 'txt') {
chmod($file, 0660);
}
}
Or you could use glob
<?php
$files = glob('./*.{txt}', GLOB_BRACE);
foreach($files as $file) {
// check here so you don't have to do every file again
if (substr(sprintf('%o', fileperms($file)), -4) === "0660") {
echo "skipping " . $file;
continue;
}
$extension = pathinfo($file)['extension'];
if ($extension === 'txt') {
chmod($file, 0660);
}
}