PHP hidden directories - Windows -
i'm attempting add feature our intranet, allow users log onto intranet, , access documents stored within windows network san.
at moment, i've retrieved file , folder names within specified users 'my documents'.
i'm having difficulty removing hidden files , folders array. @ moment, can remove folders , files starting .
.
however on windows, they're being marked 'hidden' in properties. i've googled , found lots of resources how mark file hidden, , how hide files start .
, none on how remove hidden windows files / folders. 1 post on stackoverflow mentions use directoryiterator, @ moment, haven't explained @ how use check if files marked hidden.
we have on 1000 users, approximately 500mb - 1gb of documents, multiple layers of directories, needs relatively fast.
for clarification: during recursive iteration on windows system, how can find out whether directory hidden or not, without relying on prepended .
symbol?
ok, worked out, exec()
function, use care! i'm using codeigniter, i've modified directory_helper.php
function slightly, installed on windows box, it'll need check hidden files, should work non-codeigniter sites:
function directory_map($source_dir, $directory_depth = 0, $hidden = false) { if ($fp = @opendir($source_dir)) { if(!$hidden) { $exclude = array(); exec('dir "' . $source_dir . '" /ah /b', $exclude); } $filedata = array(); $new_depth = $directory_depth - 1; $source_dir = rtrim($source_dir, directory_separator).directory_separator; while (false !== ($file = readdir($fp))) { // remove '.', '..', , hidden files [optional] if ( ! trim($file, '.') or ($hidden == false && $file[0] == '.') or ($hidden === false && in_array($file, $exclude))) { continue; } if (($directory_depth < 1 or $new_depth > 0) && @is_dir($source_dir.$file)) { $filedata[$file] = directory_map($source_dir.$file.directory_separator, $new_depth, $hidden); } else { $filedata[] = $file; } } closedir($fp); return $filedata; } return false; }
this scanned 2207 files, , 446 folders in approx 11 seconds (ages know, best do). tested on 500 folders , 200 files, , did in around 3 seconds.
its recursive function scan each non-hidden directory. first thing scan current directory hidden files , folders using exec('dir *directory* /ah /b')
function.
it store results in array , make sure current file/directory being read isn't in array.
Comments
Post a Comment