Reading files from network drives in Perl

I am working on a perl script that performs an inventory of a document for pdf files in all directories, starting from some root directory on our network. The script works fine locally, but I can't get it to read files from a 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 Tk Gui to get the catalog

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

capture all files and folders in the 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 network use

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

Please excuse my starter code. My question is that I am doing something wrong with a network drive or if I should ask the administrator for rights. Thanks ton, Dan

+4
source share
1 answer

A drive is a disk. You can pass any of the following lines:

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

You can even pass the name UNC.

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

Of course, you may need some escaping to create a string.

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

But this is probably not relevant, as you seem to get the string from Tk, rather than creating it.

There is an error in your code.

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

it should be

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

and probably

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

g doesn't make sense there and can cause problems (although I think your specific code is not suffering). Get rid of g .

+1
source

Source: https://habr.com/ru/post/1434243/


All Articles