ricksj
Technical User
- Sep 2, 2009
- 3
I'm processing hundreds of files in a directory structure that looks similar to this:
./gadget/path1
{contains several files...}
./gadget/path2
{contains several files...}
./gadget/path3
{contains several files...}
What I would like to do is print to the console progress by displaying the end path name once and only change when the path changes, such as:
Processing ./path1
Processing ./path2...
Can someone recommend a fix or an alternative method
Here's what I have coded so far;
./gadget/path1
{contains several files...}
./gadget/path2
{contains several files...}
./gadget/path3
{contains several files...}
What I would like to do is print to the console progress by displaying the end path name once and only change when the path changes, such as:
Processing ./path1
Processing ./path2...
Can someone recommend a fix or an alternative method
Here's what I have coded so far;
Code:
#!/usr/bin/perl -w
use warnings;
use strict;
use File::Find;
use File::Copy;
my $prevdir;
my $path = $ARGV[0];
chdir($path) or die "Cannot chdir to $path";
find(\&CopyContent, $path);
sub CopyContent
{
my $file = $File::Find::name;
my $dir = $File::Find::dir;
#check if file is a file (not a directory) and a Text file
if (-f $file && -T $file)
{
$dir =~ s/$path//g;
my $currdir = $dir;
if ($currdir ne $prevdir) {
print "Processing directory: \.$currdir \n";
my $prevdir = $currdir;
}
### manipulate file code goes here....
}
}