My script:
If I were to run this against the directory layout#!/usr/bin/perl -w use strict; use Cwd; # Perl script to traverse a given directory and print when each direct +ory or file is discovered. # This starts from the user's current working directory. my $dir = cwd(); my $discovered = 0; my $processed = 0; chomp (my $current = `pwd`); sub process { $dir = shift; foreach (<$dir/*>) { my $file = $_; $file =~ s/$current\///g; next if (-l $_); if (-f $_) { print "Filename: $file\nDiscovered: $discovered\nProcessed: $pro +cessed\n\n"; } if (-d $_) { print "Directory name: $file\nDiscovered: $discovered\nProcessed +: $processed\n\n"; process($_); } } } process($dir);
example_dir {file_one.txt file_two.txt next_dir {file_three.txt}} (file_one.txt and file_two.txt are inside example_dir, and next_dir is inside example_dir... file_three is inside next_dir, sorry if it's not clear)
I need to output to look like:Filename: file_one.txt Discovered: 1 Processed: 2 Filename: file_two.txt Discovered: 3 Processed: 4 Directory name: next_dir Discovered: 5 Processed: 8 Filename: file_three.txt Discovered: 6 Processed: 7
I'm trying to print when each node is discovered and processed in the stack. Can anyone help?
In reply to Help with node discovering and processing by cspctec
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |