[thelist] need to retrieve dir/file information
sasha
spam at bittersweet2.com
Fri Jan 10 12:52:03 CST 2003
On Fri, 10 Jan 2003 10:35:08 -0800, Chris W. Parker <cparker at swatgear.com>
wrote:
> hi.
>
> here is what i want to do...
>
> i'd like to retrieve (recursively) directory information, specifically
> size. when i execute the program output should be something like this...
>
> C:\dir\ 1000000
> C:\dir\1\ 303252
> C:\dir\2\ 39124
> C:\dir\2\a\ 19241242
>
> etc...
>
> also, i'd like to be able to pass the starting directory.
This is one I wrote in PHP for a web based FTP client. It should get you
started, or at least give you an idea of where to start in perl.
$dirs = array();
$files = array();
function file_tree($path) {
global $dirs, $files;
if (@$handle = opendir($path)) {
while (false !== ($file = readdir($handle))) { if ($file != "." &&
$file != "..") { if (is_dir($path . $file)) {
array_push($dirs, $path . $file . '/');
file_tree($path . $file . '/');
}
else {
array_push($files, $path . $file);
}
}
}
}
@closedir($handle);
return array(dirs => $dirs, files => $files);
}
Just feed it the starting directory, and it should go to every
subdirectory. Once you get the output, you can do anything you want with
it.
--
sasha
More information about the thelist
mailing list