qwerty80 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; my $file = "abc*.xml*"; my $searchdir = "/tst"; readDirectory($searchdir, $file); sub readDirectory { my $searchdir = shift; my $searchfile = shift; print "Searching in $searchdir \n"; # Open and close the directory opendir DIR, $searchdir or die("An error occured: $!"); my @files = readdir(DIR); closedir DIR; foreach my $currentFile (@files) { next if $currentFile =~ /^\./; if ( $currentFile eq $searchfile ) { print "Found the file: $searchdir/$curre +ntFile n"; unlink($file); } if ( -d "$searchdir/$currentFile" ) { readDirectory("$searchdir/$currentFile", $searchfile); } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Recursive search and delete
by NetWallah (Canon) on Nov 16, 2012 at 06:53 UTC | |
|
Re: Recursive search and delete
by tobyink (Canon) on Nov 16, 2012 at 09:36 UTC | |
|
Re: Recursive search and delete
by roboticus (Chancellor) on Nov 16, 2012 at 11:16 UTC | |
by tobyink (Canon) on Nov 16, 2012 at 13:03 UTC | |
|
Re: Recursive search and delete
by Arunbear (Prior) on Nov 16, 2012 at 11:59 UTC | |
|
Re: Recursive search and delete
by zentara (Cardinal) on Nov 16, 2012 at 10:54 UTC | |
|
Re: Recursive search and delete
by Tommy (Chaplain) on Nov 16, 2012 at 10:06 UTC |