What this is supposed to do is reproduce the file structure in one directory (recursively), but instead of copying the files it creates new ones with the same name (all with the same content contained in $redirect_page).
My problem is that it doesn't seem to be writing the files and only goes into one directory.my $htdocs_dir = "/home/httpd/htdocs"; my $disabled_htdocs = "/home/httpd/htdocs_disable"; check_dir("."); #takes: a directory name sub check_dir { my $dir = shift; #defined $dir || $dir = ""; my $path = "$htdocs_dir/$dir"; opendir (DIR, $path) || die "Can't open $htdocs_dir/$dir: $!"; while (defined (my $dir_file = readdir DIR)) { if (-d "$path/$dir_file") { unless ($dir_file eq '.' || dir_file eq '..') { mkdir("$disabled_htdocs/$dir/$dir_file",0755); check_dir("$dir/$dir_file"); } } elsif (-f "$path/$dir_file") { add_file("$dir/$dir_file") } } #takes: file (with path) sub add_file { my $file = shift; open FILE, ">$disabled_htdocs/$file" || die "Can't open $file: + $!"; print FILE $redirect_page; print "wrote $disabled_htdocs/$file\n";##!! this never prints close FILE; } }
thanks, a very tired melguin.
In reply to simple recursive sub from hell. by melguin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |