Ashes.cfg has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I am currently running a script where I want to store the result files onto a shared drive. for the time being since i am the only one whose running the script. I am mapping the network drive on my computer as H: and storing the files. But what if someone else wants to run the script from the shared drive. for eg..if the network drive(shared drive) name is \\wonderland\\alice how to i write it in Perl. currently what i am doing is $filepath = 'H:\\alice\\'; Can i do something so that i dont need to map it and directly use the shared drive name. is there a way i can directly assign a variable as direct path i tried $filepath='\\wonderland\\alice\\' but it doesnt work. pl help me.I have been stuck here since a couple of weeks..its urgent Thanks in advance Ashes.cfg

Replies are listed 'Best First'.
Re: Does Perl Support Absolute paths
by kyle (Abbot) on Nov 07, 2007 at 20:03 UTC

    Share drive paths under windows start with two backslashes. Since they have to be escaped in your strings, you need:

    $filepath = '\\\\wonderland\\alice\\';

    I don't use Windows, so I don't know for sure, but I'd expect this to work.

Re: Does Perl Support Absolute paths
by halley (Prior) on Nov 07, 2007 at 20:58 UTC
    These are called UNC paths, not absolute paths.

    As shown above,

    print '\\\\netbiosname\\sharename', $/;
    results in
    \\netbiosname\sharename
    I would not recommend the suggestion to emply the "net use" command to temporarily connect such a UNC path to a drive letter. It may simplify path handling but it's just as easy to accidentally run into conflicts with which drive letter to assign, whether you can disconnect the drive letter when done, or which drive letter was assigned when you save these strings.

    --
    [ e d @ h a l l e y . c c ]

      Why shell out if you can do this from within the script, with better chance to handle errors (if any).

      use Win32::FileOp qw(Map); Map 'H:' => '\\\\server\\share', {persistent => 1} or die "Failed to map the drive: $^E\n"
        Thanks a lot monks regarding this issue. I would rather run it directly from the UNC path(and not absolute path..thank you for that too) as there would be 10-15users running the script from their WorkMachine and I dont knw which drive is available for them to map it on. I will definitely try this when I reach work tommorrow. Sincere Thanks Ashes.cfg
A reply falls below the community's threshold of quality. You may see it by logging in.