James wrote:
>
> hi, all!
Hello,
> friday while trying to clean up a directory, i thought i
> could bang out a quick-and-dirty perl script that would
> let me achieve what i needed, to delete all text files in
> a subdirectory that contain a specified string. i was able
> to use the perl comman
I'm not sure if you want to find the string _in_ the file, or in the
filename.
#in the file
use strict;
opendir(DIR,".");
foreach(readdir DIR){
if(HasText($_)){
unlink $_;
}
}
sub HasText{
my $file = $_[0];
open(FILE,"$file");
while(){
if($_ =~ /pa
IL PROTECTED]>
Sent: Monday, July 15, 2002 4:13 PM
Subject: Re: unlinking all files that contain a specified string
> What about (assuming *nix)
>
> use strict;
>
> my $search_string = "Whatever you want to find";
>
> my @found = `grep -ls $search_string *`;
> chom
What about (assuming *nix)
use strict;
my $search_string = "Whatever you want to find";
my @found = `grep -ls $search_string *`;
chomp( @found );
unlink( @found );
or are you working under Windows?
- Original Message -
From: "james" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Mon