Last active
August 26, 2018 18:30
-
-
Save vijinho/630a2a49ef19a6833a350ce04d1c5f5a to your computer and use it in GitHub Desktop.
get all files (and optionally dirs) in a dir path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
// get all files in a dir path, | |
function get_all_files($dir, $ignore_dirs = true) { | |
static $alldirs = array(); | |
$dirs = glob($dir . '/*'); | |
if (count($dirs) > 0) { | |
foreach ($dirs as $newdir) { | |
if (!array_key_exists($newdir, $alldirs)) { | |
$alldirs[$newdir] = $newdir; | |
} | |
} | |
} | |
foreach ($dirs as $dir) { | |
get_all_files($dir); | |
} | |
foreach ($alldirs as $k => $v) { | |
if ($ignore_dirs && is_dir($k)) { | |
unset($alldirs[$k]); | |
} | |
} | |
natcasesort($alldirs); | |
return $alldirs; | |
} | |
// set the file time to minimum of | |
// access time, creation time, modified time | |
$files = get_all_files('/Users/vijay/Pictures'); | |
foreach ($files as $k => $file) { | |
echo "\n$file"; | |
$ctime = min(filectime($file), filemtime($file), fileatime($file)); | |
touch($file, $ctime, $ctime); | |
echo "\n\t" . date('r', $ctime); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment