Well, I wouldn't expect this to work on ANY machine because of these two adjacent lines:
chdir($dir);
if(!($dp = opendir($dir))) die ("can't open $dir.");
opendir() looks for $dir to be a subdir of the current working directory... but you change the working diretory with chdir() on the previous line. That means if $dir is "docs", that function will only work if you have a directory named docs/docs beneath the current working directory, and even then it will traverse the nested docs, not the outer one.
Take care,
Nik
http://www.bigaction.org/