Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Cannot copy from network drive

by skyler (Beadle)
on Jun 09, 2003 at 18:26 UTC ( [id://264422]=perlquestion: print w/replies, xml ) Need Help??

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

Dear monks , I'm hitting the wall on this one could you take a look at this code. I'll appreciate any ideas. Thanks!
028749|0011960|999-99-9999|GREER|SHELDON|5/23/2003|ABCDE|ABDEL-WAHAB, +MAY|ABDEL-WAHAB, MAY|ABCDE/PHYSICIAN/WEEKLY PROGRESS NOTE|A2901006|6/ +5/2003|H:\APPS\ABCDE\DB\ABCDE\13\00004FE5.008 #! perl -w use strict; use File::Copy; my $infile = "C:/radtrans/doclisth.chr"; my ( $yr, $mo, $dy ) = (localtime)[5,4,3]; my $outfile = sprintf( "C:/radtrans/%04d%02d%02d.txt",$yr+1900,$mo+1,$ +dy ); my $staticdir = "C:\\radtrans\\"; open IN, "<$infile" or die "Couldn't open $infile, $!"; open OUT,">$outfile" or die "Couldn't open $outfile, $!"; while (<IN>) { chomp; my @fields = split /|/; my $newfile = $fields[0]; my $path_str = $fields[12]; do { warn "Empty field 13"; next } unless $path_str; my @path = split /\\/, $path_str; my $dir = join "\\", @path[ 0, 1, 2, 3, 4, 5, 6 ]; $newfile =~ s/$/.rtf/; my $out = join ('|', @fields[0..9]) . "@" . $staticdir . $newfile; print OUT "$out\n"; process_dir($dir,$newfile); } close IN; sub process_dir { my ($dir, $newfile) = @_; do { warn "$dir does not exist!\n"; return } unless -e $dir; opendir DIR, $dir or do { warn "Could not open $dir $!\n" ; return }; while ( my $file = readdir DIR ) { print "dir: $dir file:$file newfile:$newfile\n"; #before the next unless statements. next unless -f "$dir\\$file"; next unless $file =~ m/\.rtf$/i; copy( "$dir\\$file", "C:\\temp\\$newfile" ) or die "Failed to copy $file: $!\n"; } }

Replies are listed 'Best First'.
Re: Cannot copy from netowrk drive
by AcidHawk (Vicar) on Jun 09, 2003 at 18:54 UTC

    You didn't really tell us what you are having trouble with but try this

    Put a \ in front of your | in the split line.. something like

    my @fields = split /\|/;

    -----
    Of all the things I've lost in my life, its my mind I miss the most.
      AcidHawk, I appreciate your reply. If the file has pipes as a delimeter. Do I need to split the line wih pipes? Is there any way that I could pass the string to a variable then I would get the path at the end of the string. For example: var1@ = 0..12; $path = 12; I'll apreciate any suggestions.

          If the file has pipes as a delimeter. Do I need to split the line wih pipes?

        You are already doing this but you probably want something more like,

        @var1 = split/\|/;
          Is there any way that I could pass the string to a variable then I would get the path at the end of the string

        When you seperate the line with pipes "|" you put the values of the entire line in an array. All you have to do is point the path variable to the last element of the array. Something like,

        $path = $var1[$#var1];
        Hope this helps, I'm not sure I understood you question properly..

        -----
        Of all the things I've lost in my life, its my mind I miss the most.
Re: Cannot copy from network drive
by gellyfish (Monsignor) on Jun 09, 2003 at 21:08 UTC
    Not a Perl answer. You say "network drive" but are showing a local drive in the code. If your real code is trying to access a network drive are you running this code from a scheduled job or some other non-interactive process? Have you tried to connect to the file using it's UNC path, i.e. "//server/share/path" ? Some non-interactive jobs may not have access to the network shares because of the permissions of the user that they run as and you will almost certainly not have any mapped network drives unless you have explicitly done it in your code. You should also be printing $! when you encounter an error as this will help diagnose the problem.
    /J\
    
      Gellyfish, Thanks for your answer. How would you recode the code to make it UNC? I'm reading the file and the path is the last field. I'll appreciate your help.
Re: Cannot copy from netowrk drive
by mikevanhoff (Acolyte) on Jun 09, 2003 at 18:44 UTC
    Maybe I have missed something, I am very new to Perl, but if you are running this on an intel (non unix) you probably need to use a backslash \ instead of a forward slash /. You will also need to escape the backslash as you have on other places i.e. this my $infile = "C:/radtrans/doclisth.chr"; shoul be my $infile = "C:\\radtrans\\doclisth.chr";

      You can actually use a forward slash in paths on a non unix platform.. I personally find it neater than escaping all the \'s

      I think that this H:/APPS/ABCDE/DB/ABCDE/13/00004FE5.008

      looks better that this H:\\APPS\\ABCDE\\DB\\ABCDE\\13\\00004FE5.008

      -----
      Of all the things I've lost in my life, its my mind I miss the most.
      This is not really answering the question because I think AcidHawk is correct. I do suggest, however, that you read this file tutorial mikevanhoff.

      Update:
      Acidhawk's post above was not there when I wrote this. I was agreeing with his/her post below. But, AcidHawk's post right above mine suggests what you will learn in the link to tachyon's file tutorial in my pre-update post. ++AcidHawk.
Re: Cannot copy from network drive
by Cody Pendant (Prior) on Jun 10, 2003 at 01:17 UTC
    Not a Perl answer either, just a note of concern -- I do hope you've changed the names of the doctor and patient involved in this obviously-medical information. If not I suggest you go back and do so... All it takes in one person to find this via Google...
    --
    “Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.”
    M-J D

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-25 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found