in reply to change files names bug

Can you try this version and report its output.

#!/usr/bin/perl use strict; use warnings; opendir(DIR, "/samplesA") or die "Can not open folder, $!\n"; my @files = readdir(DIR); closedir (DIR); open my $barcodes, "<", "/ID.txt" or die "Can not open barcode file, $ +!\n"; my @lines=(<$barcodes>); close $barcodes; for my $file (@files) { next unless $file =~ m/fq$/; foreach my $line (@lines) { chomp $line; my ($id, $barcode) = split(/\t/,$line); if ($file =~ m/$barcode/) { my $new = $file; $new =~ s/sample_$barcode/$id/; rename ($file, $new) or die "Can not change $file to $new, $! +\n"; } } }

Perhaps strict and warnings will help

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re^2: change files names bug
by Yuma248 (Initiate) on Nov 01, 2013 at 02:58 UTC

    Not, the strict and warning did not solve the problem, but I notice that when the folder contain few files (less than 20) the original scrip finish the job without problems. When the folder contain more files the original scrip stop working when it fund a file that does not have any barcode in the name. Any idea?