SitePoint Sponsor |
|
User Tag List
Results 1 to 1 of 1
Thread: Printing unique pathnames
-
Oct 13, 2009, 17:34 #1
- Join Date
- Aug 2006
- Posts
- 19
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Printing unique pathnames
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;
Code Perl:#!/usr/bin/perl -w use warnings; use strict; use File::Find; use File::Copy; my $prevdir; my $path = $ARGV[0]; chdir($path) or die "Can\'t chdir to $path"; print "Copying index.html file...\n"; 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.... } }
Bookmarks