in reply to Execute error on opendir

Are you sure the $element is the full path to the directory you want to open - or else you are executing this script from the correct place s.t. $element is a relative directory from your cwd? You can confirm this with: die "no dir named $element\n" unless ( -d $element); just before your opendir stmt.

Replies are listed 'Best First'.
Re: Re: Execute error on opendir
by mikevanhoff (Acolyte) on Aug 14, 2002 at 14:07 UTC
    stajich I added the line of code you provided, and it appears that $element is trying to use a relative path. Any suggestions on how to correct this?
      It's always safest(not sure if it's required) to give opendir an absolute directory name - that is, a directory name with a fully qualified path. Do the "element"s in /Scripts/rotlog have absolute directory names in them?

      And, the $name that readdir returns is *NOT* an absolute filename. Therefore, before you try to test $name with a -M filetest operator, you must provide the absolute path to $name - something like this:
      my $current_abs_dir = "/path/to/opendir/directory"; while ($name = readdir(REP)) { $abs_name = "$current_abs_dir/$name"; if (-M $abs_name >= 10) {
      If the elements in /Scripts/rotlog do not include the absolute path to the directory, you'll need to get the absolute path to the directory from somewhere.

      Read the perldocs for opendir and readdir by doing
      perldoc -f opendir perldoc -f readdir
      HTH.
        Thanks, and yes the lines in /Scripts/rotlog are absolute paths. I want to read the contents of the dir in each line (path) of the /Scripts/rotlog file into the array. The issue is using the array elements instead of hard coding the paths.
      Add a $prepath = '/some/path/to/that/makes/elementfullyqual' right below the shabang, then rewrite the open and -d test with "$prepath$element"...

      -Waswas
        Thanks, but that made matters worse. The contents of the 'rotlog" file are fully qualified directory paths. Any other ideas?