.seg
파일 위에 두 개의 폴더가있는 폴더의 이름을 포함하도록 각각 찾은 .seg
파일의 이름을 바꾸는 방법을 찾고 있습니다. 예를 들어Perl에서 일괄 이름 바꾸기 및 파일 이동
나는
/data/test_all_runs/TestRun/Focus-HD753/QC/diffCoverage.seg
에
.seg
파일을 발견하고 내가
/data/test_all_runs/TestRun
로 이동하고자하는 파일의 이름을 변경 일단
Focus-HD753.seg
이름을 변경하고 싶습니다
또는 $ARGV[0]
입니다. 당신이 File::Basename
모듈을 사용할 수있는 이름을 파일 이름 변경에 대한
#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
use File::Spec;
my $home = "/data";
my @location_parts = ($home, 'test_all_runs');
push @location_parts, $ARGV[0] if @ARGV;
my $location = File::Spec->catdir(@location_parts);
my @moves;
my @vcf_moves;
sub find_seg {
my $F = $File::Find::name;
if ($F =~ /\.seg$/) {
my @path_parts = File::Spec->splitdir($F);
my $name = $path_parts[-3];
my $target = File::Spec->catdir($location, "$name.seg"); print $target;
push @moves, [ $F, $target ];
}
}
find({ wanted => \&find_seg, no_chdir => 1 }, $home);
while (@moves) {
my ($F, $target) = @{ shift @moves };
warn "$F -> $target";
rename $F, $target or warn "Can't move to $target";
}
sub find_vcf {
my $V = $File::Find::name;
if ($V =~ /(vcf$|oncomine\.tsv$)/) {
my @path_parts = File::Spec->splitdir($V);
print "The path_parts at 0 is #############".$path_parts[0]."\n";
print "The path_parts at -1 is #############".$path_parts[-1]."\n";
print "The path_parts at -2 is #############".$path_parts[-2]."\n";
print "The path_parts at -3 is #############".$path_parts[-3]."\n";
print "The path_parts at 1 is #############".$path_parts[1]."\n";
my $target_vcf = File::Spec->catdir($location, $path_parts[-1]); print $target_vcf;
push @vcf_moves, [ $V, $target_vcf ];
print "$V\n";
}
}
find({ wanted => \&find_vcf, no_chdir=>1}, $home);
while (@vcf_moves) {
my ($V, $target_vcf) = @{ shift @vcf_moves };
warn "$V -> $target_vcf";
rename $V, $target_vcf or warn "Can't move to $target_vcf";
}
일반적으로 현재 코드에서 작동하지 않는 것이 무엇인지, 즉 사용자가 이해하지 못하는 것을 알려주는 것이 좋습니다. –
"또는 $ ARGV [0]"또는 "$ ARGV [0]"으로 연결 하시겠습니까? – choroba
실제로 "test_all_runs"에서 하나의 디렉토리 인 "TestRun"으로 이름이 바뀐 .seg 파일을 옮겨야합니다. 이 폴더의 이름은 항상 다르지만/data/test_all_runs는 항상 동일합니다. 덕분에 – user3781528