forked from theonemule/gphoto-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht.php
executable file
·43 lines (40 loc) · 1.22 KB
/
t.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
function getDirContents($path) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
$files = array_filter(iterator_to_array($iterator), fn($file) => $file->isFile());
return $files;
}
function getDirContents_p($path) {
$directory = new RecursiveDirectoryIterator($path, FilesystemIterator::FOLLOW_SYMLINKS);
$filter = new \RecursiveCallbackFilterIterator($directory, function ($current, $key, $iterator) {
// Skip hidden files and directories.
if ($current->getFilename()[0] === '.') {
return FALSE;
} else if ($current->isDir()) {
// Only recurse into intended subdirectories.
# return $current->getFilename() === 'wanted_dirname';
return TRUE;
} else if ($current->isFile()) {
return TRUE;
} else {
// Only consume files of interest.
#return strpos($current->getFilename(), 'wanted_filename') === 0;
return FALSE;
}
});
$iterator = new \RecursiveIteratorIterator($filter);
$files = array();
foreach ($iterator as $info) {
$files[] = $info->getPathname();
}
return $files;
}
$files = getDirContents_p('/srv/shifucc');
#var_dump($files);
echo "<br/>";
foreach ($files as $file) {
# var_dump($file);
# echo "<br/>";
echo "<li>Path: ".$file."</li>";
}
?>