LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-19-2009, 05:49 AM   #1
Verve1986
LQ Newbie
 
Registered: Nov 2007
Posts: 6

Rep: Reputation: 0
[solved] Perl: directories given to opendir via foreach give "No such file" error


Hi there,

I'm writing a perl script to remove a test database and part of that is of course getting rid of all files. So I wrote this to do the job:

Code:
    @rm_opendirs = ($orahome . $dsep . $spfile_dir,$orahome . $dsep . "rdbms" . $dsep . "trace");
    foreach $dir (@rm_opendirs) {
        opendir($fh,$dir) or return("ERROR","Could not open " . $orahome . $dsep . $spfile_dir . " for reading: $! .",$debug_info);
        while ($file = readdir($fh)) {
            if ($file =~ m/$pattern/i)
            {
                push(@rm_paths,$dir . $dsep . $file)
            }
        }
        closedir($fh);
    }
    foreach $path (@rm_paths) {
        rmtree($path,1,1);
    }
This always results in an "Could not open /u00/app/oracle/product/10.2.0/rdbms/dbs for reading: No such file or directory" (that directory is the one ending with the $spfile_dir variable) message, although that directory exists and the executing user has writing rights on it.

The same behaviour if I create the directory array like this:

Code:
    push(@rm_opendirs,$orahome . $dsep . $spfile_dir);
    push(@rm_opendirs,$orahome . $dsep . "rdbms" . $dsep . "trace");
The problem does not occur when one of the directories is the only element in the array though. Of course I could copy and paste that part of the script for the second directory, but I don't like that workaround

Any help would be appreciated.

Thank you.

Last edited by Verve1986; 02-19-2009 at 05:55 AM.
 
Old 02-19-2009, 05:54 AM   #2
Verve1986
LQ Newbie
 
Registered: Nov 2007
Posts: 6

Original Poster
Rep: Reputation: 0
of course I see the error only when I post it to a forum...

Had the error message hard coded to the first directory when in fact the second one was the problem.

Solved, sorry for wasting that database space
 
  


Reply

Tags
foreach, perl



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying files and sub-directories of a directory except the directories named ".abc" sri1025 Linux - General 2 08-24-2010 08:53 AM
Error: "libdmx.so.1: cannot open shared object file: No such file or directory" ESC201 Linux - Software 4 11-01-2008 08:38 PM
New and upgraded packages give "No such file or directory" error. Lickwid Arch 3 09-03-2008 12:52 PM
PERL: Help w/ "foreach" loops and building a Crontab entry - Just need some advice bpmee Programming 5 10-13-2006 02:12 PM
error "Perl(File::Basename)" is needed by application RohanShrivastav Linux - Newbie 2 12-15-2004 12:05 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration