일부 보관 파일이있는 디렉토리를 읽고 하나씩 보관 파일을 압축 해제하고 있습니다.Perl의 다른 위치에 tar 파일 보관
모든 것이 잘 보이지만 파일은 하위 모듈을 실행하는 주 perl 코드 모듈이있는 폴더에서 압축되지 않은 상태가됩니다.
내가 지정한 폴더에 아카이브를 생성하고 싶습니다.
sub ExtractFile
{
#Read the folder which was copied in the output path recursively and extract if any file is compressed
my $dirpath = $_[0];
opendir(D, "$dirpath") || die "Can't open dir $dirpath: $!\n";
my @list = readdir(D);
closedir(D);
foreach my $f (@list)
{
print " \$f = $f";
if(-f $dirpath."/$f")
{
#print " File in directory $dirpath \n ";#is \$f = $f\n";
my($file_name, $file_dirname,$filetype)= fileparse($f,qr{\..*});
#print " \nThe file extension is $filetype";
#print " \nThe file name is is $file_name";
# If compressed file then extract the file
if($filetype eq ".tar" or $filetype eq ".tzr.gz")
{
my $arch_file = $dirpath."/$f";
print "\n file to be extracted is $arch_file";
my $tar = Archive::Tar->new($arch_file);
#$tar->extract() or die ("Cannot extract file $arch_file");
#mkdir($dirpath."/$file_name");
$tar->extract_file($arch_file,$dirpath."/$file_name") or die ("Cannot extract file $arch_file");
}
}
if(-d $dirpath."/$f")
{
if($f eq "." or $f eq "..")
{ next; }
print " Directory\n";# is $f";
ExtractFile($dirpath."/$f");
}
}
}
ExtractFile가 재귀 적으로 모든 아카이브 루프에 호출되는 방법
이 내 코드입니다. $tar->extract()
을 사용할 때이 메서드를 호출하는 폴더에서 압축이 풀립니다. 아카이브에
해당 파일 : 나는
$tar->extract_file($arch_file,$dirpath."/$file_name")
를 사용하는 경우는 오류가 발생합니다 '/home/fsang/dante/workspace/output/s.tar을'/ 홈/fsang/단테/lib 디렉토리에 /Extraction.pm line 80
해당 경로와 입력 결과를 확인하는 데 도움이되도록 문제가 없습니다.
일부 사용상의 문제가 있습니다. $tar->extract_file()
을 모르겠습니다.
이 문제를 해결해 주신 모든 분들께 감사드립니다.
감사합니다,
아니요, 당신은 오타가있는 사람입니다. 귀하의 "고정"라인에 따옴표가 홀수로 표시됩니다. – cjm
여전히 동일한 오류 메시지가 나타납니다. –
감사합니다. @cjm - 줄 끝 부분에 인용 부호를 잊어 버렸습니다. – Axarydax