디렉토리 및 .tar.gz 파일을 찾는 스크립트가 있습니다. 어떤 이유 (즉, 나는 당신이 나를 도울 수 바라고 무엇) 내Perl 디렉토리 찾기가 작동하지 않습니까?
if (-d $file)
이 디렉토리의 것을 반환하지 않습니다!
내 스크립트 :
# specify the directory where you want to start the search
my $directory = $ARGV[0];
my $directoryCount = 0;
# Calling the Subroutine, which searches the File
readDirectory($directory);
sub readDirectory
{
my $directory = shift;
my $searchfile = shift;
my @directories;
my $tarOuput;
# a little bit output, in which directory the script
# is searching at the moment (the following line is not necessary)
print "Searching in $directory\n\n";
# Open and close the directory
opendir(DIR, $directory) or die("ERROR: Couldn't open specified directory $!");
my @files = readdir DIR;
closedir DIR;
shift(@files);
shift(@files);
print "------------------------------------------------------------------------ \n\n";
foreach my $currentFile (@files)
{
print "Current File:", $currentFile, "\n\n";
if (-d $currentFile) #THIS DOESN'T WORK?!?!?!?!?
{
print "Directory: ", $currentFile, "\n\n";
#push (@directories, $currentFile);
#print "Found new directory: $directories[$directoryCount]\n\nCurrent number = $directoryCount\n\n";
#$directoryCount++;
#print "Directories: ", @directories, "\n\n";
#next;
# The Subroutine is calling hisself with the new parameters
#readDirectory($currentFile); #recursive call through sub-directories
}
elsif ($currentFile =~ /\.tar.gz$/i || $currentFile =~ /\.tar$/i)
{
print "File: ", $currentFile, "\n\n";
my $tarOutput = `tar -tvzf $currentFile`;
print $tarOutput, "\n";
}
print "----------------------------------------------------------------------- \n\n";
}
}
이 디렉토리는 결코 인쇄 경우 $ currentFile를 인쇄 할 인쇄 문 ...
는 출력 :
Searching in /home/gackerma/Logs
------------------------------------------------------------------------
Current File:Dir1
-----------------------------------------------------------------------
Current File:file
-----------------------------------------------------------------------
Current File:configs.tar.gz
File: configs.tar.gz
tar (child): configs.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
-----------------------------------------------------------------------
Current File:adstatlog.299
-----------------------------------------------------------------------
Current File:adstatlog.tgz
-----------------------------------------------------------------------
내가 수행 한 같은 디렉토리에 슈퍼 간단한 스크립트로 똑같은 일을하고 그것은 작동하지만 ... 아니, 아니, 여기. 나는 무엇이 잘못되었는지 이해하지 못한다 ...?
도와주세요.
예 즉 교대가 무엇인지입니다. 고마워요! – user2340116
@ user2340116 이가 지금은 분명합니까? 아니면이 diff 출력을 읽는 데 문제가 있습니까? – chrsblck
IT WORKED !!! 아, 고마워요! 전체 디렉토리 경로가 핵심입니다. – user2340116