brian54321uk wrote:
Aruna Goke wrote:
Mr. Shawn H. Corey wrote:
On Fri, 2008-09-05 at 19:09 +0100, brian54321uk wrote:
HI again
I would like to test a folder full of files, and if a file contains abc123blue or xyz357green then that file is to be deleted.
What would be the best way of achieving this please?

If however, it would be simpler for the script to empty the files contents, that's not a problem as I have another script that I can run which deletes empty files.

thanks
Brian


To delete a file, see `perldoc -f unlink`.
To empty a file, see `perldoc -f truncate`.


do you mean if the content of the file contains "abc123blue || xyz357green" or if the filename contains abc123blue || xyz357green.


goksie



If a file contains the data.



#!/usr/bin/perl

use warnings;
use strict;

# open the directory.

my $dirname = 'path-to-your-directory';

opendir DH, $dirname or die "cannot open $dirname: $!";
while(my $filname=readdir(DH)){
open FH, "<", $filname or die "Cannot open $filname:$!";
   while(<FH>){
   print $filname, if/abc123blue|xyz357green/; #for debugging purpose
   unlink $filname, if/abc123blue|xyz357green/;
   }
}





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to