Thanks to all for the input ..<br><br>this is what I ended up with .. that worked ..<br><br>find sub { push(@tmp ,$File::Find::name, "\n") }, $tmp_dir;<br><br><br>while (<@tmp>){<br> chomp;<br> $_ =~ s/$tmp_dir//;
<br> $_ =~ s/^\///;<br> my $line = $_;<br><br> <br> if( $line =~ /^\+\w+/i ) {<br> print "TO DELETE - $line\n";<br> push(@del_files, $line);<br><br> } else {<br> if ( ($line =~ /^\n/) || ($line =~ /tmp\/translate/) || ($line =~ /^\/files/)){ #do nothing
<br> } else { # add to array<br> print "ADD TO file - $line\n";<br> push(@ctr_file , $line);<br> }<br> } <br> <br>}<br><br><div><span class="gmail_quote">On 6/29/06, <b class="gmail_sendername">
Jonathan McKeown</b> <<a href="mailto:jonathan@hst.org.za">jonathan@hst.org.za</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Thursday 29 June 2006 07:37, Gregory Machin wrote:<br><br>> find sub { push(@tmp ,$File::Find::name, -d && '/', "\n") }, $tmp_dir;<br>><br>> #find all files starting with a plus<br>> foreach (@tmp) {
<br>><br>> $_ =~ s/$tmp_dir\/// ; # remove the path to the input working dir so<br>> only<br>> # the files and directories in the working dir are used<br>> $_ =~ s/\/$//; #remove trailing "/"
<br>> # /^\+\w+/i filter all files starting with "+"<br>> if ($_ =~ /^\+\w+/i ){ push(@del_files, $_); $_ = "0"; } # filter and<br>> pass files starting with + to @del_files for removale
<br>><br>> #print "$_";<br>> if ($_ ne "0"){<br>> push(@ctr_file , "$_");<br>> print "$_";<br>> }<br>> }<br><br>Nick Cleaton pointed out that in the find line, you're pushing three values
<br>onto the @tmp array for each filename, which accounts for your "\n"s. The<br>middle value is either an empty string, for non-directories, or '/' for<br>directories. / is not the ideal value to have occurring in a list of files
<br>and directories for deletion.<br><br>Depending whether you need the @ctr_files list or not, you might try either<br><br>find sub { push @tmp, $File::Find::name }, $tmp_dir;<br>for my $file (@tmp) {<br># $file =~ s!^$tmp_dir/!!;
<br> if ($file =~ /^\+/) { push @del_files, $file }<br> else { push @ctr_files, $file }<br>}<br><br>or<br><br>find sub { push @tmp, $File::Find::name }, $tmp_dir;<br>#@tmp = map { s!^$tmp_dir/!! } @tmp;
<br>@del_files = grep { /^\+/ } @tmp;<br><br>The second one doesn't create @ctr_files (obviously). In both cases you can<br>include or leave out the commented line which removes $tmp_dir/ from the<br>start of the full pathname, depending whether you want an absolute or
<br>relative path to the file. (I've used ! as the delimiter in the s/// rather<br>than the usual /, because it saves escaping the / on the end of the dirname.<br>Remember you can use anything as the delimiter for quote-like operators).
<br><br>You've called your arrays @del_files and @ctr_files: they will also contain<br>directories. One way to eliminate all directories from the lists is to change<br>your find line to<br><br>find sub {<br> my $name = $File::Find::name;
<br> push @tmp, $name unless $name eq $File::Find::dir;<br> }, $tmp_dir;<br><br>Jonathan<br>_______________________________________________<br>Za-pm mailing list<br><a href="mailto:Za-pm@pm.org">Za-pm@pm.org
</a><br><a href="http://mail.pm.org/mailman/listinfo/za-pm">http://mail.pm.org/mailman/listinfo/za-pm</a><br></blockquote></div><br><br clear="all"><br>-- <br>Gregory Machin<br><a href="mailto:greg@linuxpro.co.za">greg@linuxpro.co.za
</a><br><a href="mailto:gregory.machin@gmail.com">gregory.machin@gmail.com</a><br><a href="http://www.linuxpro.co.za">www.linuxpro.co.za</a><br><a href="http://www.exponent.co.za">www.exponent.co.za</a><br>Web Hosting Solutions
<br>Scalable Linux Solutions <br><a href="http://www.iberry.info">www.iberry.info</a> (support and admin)<br><br>+27 72 524 8096