Perlwannabe wrote:

> Still having problem with unlink.  My original problem began with deleting
> files from a list.  I seem to have fixed the problem reading the list but
> the unlink does not work.
> 
> Here is the test script that I am working from:
> 
> my $file = 'listitems.txt';
> open my $fh, $file or die "Cannot open $file: $!";
> while($Line = <$fh>) {
> chomp($Line);
> my $del = "*$Line*.*";
> my $complete = "c:/testdir/$del";
> unlink glob $complete or die "unlink failed: $!";
> }
> 
> A sample of the contents of the 'listitems.txt' file is:
> 
> item997
> item996
> item999
> item983
> 
> 
> The directory c:/testdir/ contains many files, but I want to delete the
> files with any *item###*.* from the directory.  So if the directory has
> 3000 files I want to delete every file that has item997 in it.
> 

glob returns the relative path of the files so if you are in a different 
directory (other than c:/testdir) executing the script, it will not find 
the files. try fully qualify the path:

#!/usr/bin/perl -w
use strict;

open(FH,"listitems.txt") || die $!;
unlink map{chomp; glob "c:/testdir/*$_*.*" } <FH> or die $!;
close(FH);

__END__

or:

[x]$ perl -lne 'unlink glob "c:/testdir/*$_*.*" or die $!' listitems.txt

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to