views:

49

answers:

2

How would you explore and write to windows shared directories in perl ? Note: I don't have the right for network drive creation on the concerned workstation. I tried (without results) the following :

my $ROOTDIR1 = 'c:/';
my $ROOTDIR2 = '//server/dir1/dir2/';
sub dtest {
  my $ROOTDIR = shift;
  warn "Testing '$ROOTDIR'.";
  opendir( SHAREFILE, "$ROOTDIR" ) or warn "1 -> " . $!;
  my @files = <$ROOTDIR*>;
  warn ("2 -> nothing !") if (!scalar @files);
  chdir $ROOTDIR or warn "3 -> " . $!;
}
dtest($ROOTDIR1);
dtest($ROOTDIR2);

But as shown by the following output :

Testing 'c:/'. at E:\test\a.pl line 5.
Testing '//server/dir1/dir2/'. at E:\test\a.pl line 5.
1 -> No such file or directory at E:\test\a.pl line 6.
2 -> nothing ! at E:\test\a.pl line 8.
3 -> No such file or directory at E:\test\a.pl line 9.

None of those methods are working.

Any idea ?

A: 

UNC paths should have backslashes.

daxim
At least on Activestate perl, that's not the case. It maps the forwards slashes to backslashes for you so that Unix folk like me don't have to retrain our brains.
Nic Gibson
Okay, I had the suspicion that only worked for traditional file paths, but could not try it out for a lack of Windows. Thanks for confirming.
daxim
+2  A: 

UNC paths work for me, in ActivePerl 5.12.1 and Cygwin Perl 5.10.1, without a hitch. I would first of all guess that there is no path '//server/dir1/dir2' and I can only think that what you're passing is not a legitimate UNC path to wherever you're actually trying to get.

  • Barring that, is it timing out, perhaps? I know that if you do not have a drive mapped to a particular share in Windows, it can be a bear trying to bring up a network share with a bare UNC path, it can often take minutes to load in Explorer.

  • Another thing to check is perhaps this is a share that would require you to enter a password upon connecting. I'm not sure if Perl covers the signing on process in Windows. Maybe your network shares only respond to programs who know how to answer a challenge given to them by the server.

Axeman
As you said, my path isn't a legitimate UNC path : There was a right assignation issue.Thanks
OMG_peanuts