I'm making a program that allows a user to generate a HTML page of directories in a system. My issue is that I only made the code to work for linux. I need it to work for ALL operating systems. How can I do this?
#!/usr/bin/perl use strict; use warnings; ### This program looks at the current directory and then makes a path +to all the sub directories. ### Step 1: Create a subroutine with Variables for the program. This i +ncludes the following: ### Files, Path and Directories. ### Step 2: make the program list the files and folders of current dir +ectory. Push folders into an array ### Step 3: Print Dirs ### Step 4: Recurse if (@ARGV != 1) { print "Usage: perl $0 [PATH/][TO/]DIR\n"; exit; } my $path = $ARGV[0] ; sub list { my $path=$_[0]; #print "DEBUG - listing [$path]\n"; chomp(my @files = `ls -a $path`); my @dirs; foreach(@files) { if (-d "$path/$_" && $_ ne "." && $_ ne ".."){ push (@dirs , "$path/$_"); } } print "-------------------------------------\n"; print "Generating HTML doc for path = [$path]\n"; open(FHOUT, ">", "$path/index.html") or die "Can't open '$path/index.html':$!\n"; print FHOUT "<!DOCTYPE html>"; print FHOUT "<html><head>" . "<title>listing:</title>" . "</head><body>"; print FHOUT "<ol>\n"; foreach( @files ) { if ($_ ne "index.html" && $_ ne "." && $_ ne "..") { print FHOUT "<li>"; print FHOUT "<a href='$_'>Parent</a>"; } if (-d $_) { print FHOUT " (DIR)"; } print FHOUT "</li>"; #print FHOUT "<br/>\n"; } } print FHOUT "</ol>\n"; print FHOUT "</body></html>"; close(FHOUT); #foreach (@dirs) { # print "$_\n"; #} ####+++++++++++++++ ## Now visit other dirs recursively: foreach (my @dirs) { &list($_); } exit;
In reply to How to perform recursion in any OS? by rollec
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |