Note that there are some explanatory texts on larger screens.

plurals
  1. POPerl Directory Finder doesn't work?
    text
    copied!<p>I have a script to find Directories and .tar.gz Files. For whatever reason (that's what I'm hoping you can help me with) my</p> <pre><code>if ( -d $file ) </code></pre> <p>doesn't return that it's a directory!!!</p> <p>My Script:</p> <pre><code># 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"; } } </code></pre> <p>The print statement that will print the $currentFile if it's a directory never prints...</p> <p>Output:</p> <pre><code>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 ----------------------------------------------------------------------- </code></pre> <p>I've done the exact same thing with a super simple script in the same directory and it works...But nope, not here. I don't understand what's wrong...?</p> <p>Help please?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload