4

I am working on a perl script which does a document inventory for pdfs in all directories starting from some root directory on our network. The script runs fine locally, but I can't get it to read files from the network drive. i have strawberryperl

this is the beginning of my code

use strict;
use Excel::Writer::XLSX;
use Cwd;
use Tk;
use File::Find;

my @analystreports;
my @directories;

I used the Tk Gui to get a directory

my $homeDir  = Tk::MainWindow->new->chooseDirectory;

capture all files and folders in current directory

find(\&grabPDF, $homeDir);

sub grabPDF {

    my $file = $_;
    if ($file =~ /\.pdf/g) {

        push @analystreports, $File::Find::name;
    }
}

my network drive looks like this in net use

Local N: Remote \abc-file-01\shared data

Please excuse my beginner code. My question is whether I'm doing something wrong with a network drive or if I have to ask our administrator for privileges. Thanks a ton, Dan

Sean Bright
  • 118,630
  • 17
  • 138
  • 146
user1671813
  • 63
  • 1
  • 5
  • When you say you can't get it to read files, what does that mean? Do you get an error message? If so, what is the error message? I also don't understand what you mean by "my network drive looks like this..." Could you clarify? Do you have your network drive mapped to a local drive letter? – David Sep 14 '12 at 16:48
  • Sure, the network drive is mapped to the letter n. also the program just runs endlessly. no error message. i appreciate your help – user1671813 Sep 14 '12 at 17:27
  • Endlessly, or for a very long time? You're scanning an entire drive from what you said. That can take a while! – ikegami Sep 14 '12 at 17:58
  • it is endless. the time it takes makes no sense. i'm just looking in one folder. i have the same folder on my local and it works in half a second – user1671813 Sep 14 '12 at 18:58
  • 1
    Does that folder have any folders or symlinks? You are searching recursively. Why don't you add `warn($_)` to your callback sub to track its progress? What does `chooseDirectory` return? – ikegami Sep 14 '12 at 19:07
  • it has no folders contained, only a bunch of pdf's. i'll add warn. choose directory just returns a path like C:/Users/User/Desktop/... – user1671813 Sep 14 '12 at 19:22

1 Answers1

1

A drive is a drive. You can either pass any of the following strings:

N:\
n:\
N:/
n:/

You could even pass the UNC name.

\\abc-file-01\shared data
//abc-file-01/shared data

Of course, you might have to use some escaping to build the string.

"N:\\"
"N:/"
"n:\\"
"n:/"
"\\\\abc-file-01\\shared data"
"//abc-file-01/shared data"

But that's probably not relevant since you appear to be getting the string from Tk rather than building it.

There's a bug in your code.

if ($file =~ /\.pdf/g) {

should be

if ($file =~ /\.pdf/) {

and probably

if ($file =~ /\.pdf\z/) {

The g makes no sense there and can cause problems (although I think your specific code doesn't suffer). Get rid of the g.

ikegami
  • 367,544
  • 15
  • 269
  • 518
  • thanks for the help. why do you think it needs escaping for this drive and not the local? I have tried all of the other combinations. thanks for the advice on the g. – user1671813 Sep 14 '12 at 18:57
  • i mean that they way i have it coded works when i pick any folder on my hard drive. just not on the network drive. i don't get why i'd have to change the way the path is formatted if that is the case. – user1671813 Sep 14 '12 at 19:20
  • You don't. The paths should not be changed at all. – ikegami Sep 14 '12 at 19:30
  • thank you so much for your help. you were right to have me add warn($_) it just took a really long time on the network! – user1671813 Sep 14 '12 at 19:38