Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

open dir on Win32

by HamNRye (Monk)
on Jan 17, 2003 at 19:29 UTC ( [id://227769]=perlquestion: print w/replies, xml ) Need Help??

HamNRye has asked for the wisdom of the Perl Monks concerning the following question:

Greets Monks...

I am trying to monitor a directory. I am running on Windows2000 with activestate 5.6. My standard "get_dir" routine is used for both these files. (wlog just puts a timestamp on the line and writes it to a log.)

sub get_dir { my $dir = shift ; opendir(DIR, $dir) || wlog( "Cannot open dir: $dir." ); my @files = grep !/^\.\.?$/, readdir DIR ; closedir DIR; return @files ; }

The problem is that the machine I want this to run on constantly complains about not being able to read the directory... I can get the directory listing from my workstation. I have been running a script that writes out the file count and then having the other program read the file. Not optimal. Here are both code snips:

#! /usr/bin/perl # This one works sub main { @total1 = get_dir("\\\\RICH0417\\d\$\\wirein"); @total2 = get_dir("\\\\RICH0418\\d\$\\wirein"); @total = (@total1, @total2); open (F, ">E:\\wirecount.txt")|| die("Cannot open file."); print F ($#total + 1); close F; print STDOUT "."; sleep 30; main(); }
sub do_wire { #Non-working.... my @wire1 = get_dir("\\\\RICH0417\\d\$\\wirein") || wlog("Cannot get w +ire1."); my @wire2 = get_dir("\\\\RICH0418\\d\$\\wirein") || wlog("Cannot get w +ire2."); my @wiretotal = (@wire1, @wire2); my $wire = ($#wiretotal + 1); my $wire = get_file("C:\\wirecount.txt"); if ($wire < 100) { $wirestat = "green"; } else { $wirestat = "red"; } return $wire; }

Anybody have some things I can look into as far as getting this?? I have even tried:

system("net use /USER:USERNAME Q: \\\\RICH0417\\d$\\Temp PASSWORD") == + 0 && wlog("Q:\ Mounted");
to mount the drive. Note that I can mount the drive from the desktop via the usual windows methods.

Finally, from the log:

14:28 1-17-2003 >> Cannot open dir: \\RICH0417\d$\wirein. 14:28 1-17-2003 >> Cannot get wire1. 14:28 1-17-2003 >> Cannot open dir: \\RICH0418\d$\wirein. 14:28 1-17-2003 >> Cannot get wire2.

Thanks for your help...
~Hammy

Replies are listed 'Best First'.
Re: open dir on Win32
by Fletch (Bishop) on Jan 17, 2003 at 19:42 UTC

    It can be helpful to include $! in error messages so that it's clear what went wrong, not just that something failed.

      What went wrong?? Hope this helps... (Original error was $! but that did no good because I didn't get what directory couldn't be opened.) "Reason: No such file or directory"

      As far as permissions, I have quadruple checked them. I can get the directory from desktop, but when running a perl script as the logged in user, the directory cannot be found. This also works from my workstation logged in as the same user.

      15:48 1-17-2003 >> Cannot open dir: \\RICH0417\d$\wirein. Reason: + No such file or directory 15:48 1-17-2003 >> Cannot open dir: \\RICH0418\d$\wirein. Reason: + No such file or directory

      The system() call was tried, but was just to see if there was a possible workaround. I cannot believe that I would need to load a module to get a daggone directory listing.

      ~Hammy

Re: open dir on Win32
by Marza (Vicar) on Jan 17, 2003 at 20:06 UTC

    ACK! system calls! I like to keep thinks Perl. You might take a look at Win32::FileOp for doing mounts.

    As Fletch suggested, use $! to get the error message

    I do hate suggesting it, but do verify your security access on the folders inquestion.

      FileOp is good for mounting, but that is not what I really want to do. I just want to get a directories contents by using opendir(DIR, \\Server\path);

      ~Hammy

        Again check your security and you might try your computer names at lowercase.

        I ran your do_wire and get_dir(without the grep) and saw files in two folders that were not shared.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://227769]
Approved by jlk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-19 04:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found