in reply to Perl and Shared drive

Your question is a little vague. If you are trying to write you script so that other people can run the script on their computer without having to modify it, then you need to refer to the file by its network path. Instead of referring to the mapped drive name use the share name.

Example
'\\\\ComputerName\\DirName\\Filename' or
'//ComputerName/Dirname/Filename'

Here is some example code I tested on my computer of different ways to access the data.

#! /usr/bin/perl -w # Different ways to open file on another networked windows machine. # Assume: Other computers name is Zoe # The file is in the shared directory zoe_data\test # The directory zoe_data has been mapped localy to F: # The filename is test.txt @mypaths = ( '\\\\Zoe\\zoe_data\\test\\', 'F:\\test\\', '//Zoe/zoe_data/test/', 'F:/test/' ); $filename = "test.txt"; foreach $path (@mypaths) { print "\n\nOpening file [", $path . $filename, " ]\n\n"; open (IN,$path . $filename) or die "can't open the file: $!\n"; print while (<IN>); close (IN); }

I hope this answers your question.
zzspectrez

Replies are listed 'Best First'.
RE: RE: Perl and Shared drive
by Anish (Novice) on Nov 07, 2000 at 02:32 UTC
    I tried this too.suppose my servername is nj7001pdcpublic, there is directory SAPTreasTeam. then there is subdorectory under SAPTreasTeam called SWIFT.and file under that subdirectory called Swift. how would you access this in perl.I tried
    $drvSwift="//nj7001pdcpublic/SAPTreasTeam/SWIFT/Swift";
    it's not working any suggestions.

      Ok. You need to be more specific. What is not working. What is the rest of the code. What is the error returned. What type of file.

      Couple things come to mind. First of, do you have privelages to access the file? With Win98 you can set passwords for shares. With Win2k and NT files have privelages.

      If this is not the problem. The biggest thing that comes to mind looking at that path is what kind of file is it?? You have no file extension. Most files in the windows world have a file extension but they are not shown by windows. For example, if it was a text document in would be swift.txt if a word document swift.doc or if it was excel document swift.xls. Could you be accidently forgetting something simple as a file extension??

      Hope that helps!
      zzspectrez