Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Current working directory on win32

by pernod (Chaplain)
on Oct 14, 2004 at 12:47 UTC ( #399184=note: print w/replies, xml ) Need Help??


in reply to Current working directory on win32

Umm .. If you only need the working directory, I would suggest using FindBin instead, as it is platform independent.

use strict; use warnings; use FindBin; print $FindBin::Bin, "\n"; # prints c:\dev\temp\monks\

A quick glance at the POD for Win32 shows that Win32::GetLongPathName in list context returns the path and the file as two different components. It seems to me that you are trying to do this:

use Win32; my( $path, $filename ) = Win32::GetFullPathName( $0 ); my $longpath = Win32::GetFullPathName( $path ); print $longpath; # prints c:\dev\temp\monks\

Here I find the path and filename component and stuff them into variables. Then I attempt to translate $path to a long path with the second call to Win32::GetFullPathName. This works on my machine with Activestate Perl 5.8 and Windows XP.

Hope this helps.

pernod
--
Mischief. Mayhem. Soap.

Replies are listed 'Best First'.
Re^2: Current working directory on win32
by EverLast (Scribe) on Oct 14, 2004 at 12:54 UTC
    > i have written a small script to know the name of current working directory

    The original poster seems to want cwd, at least that's what he states. FindBin "Locate's directory of original perl script".

    ---Lars

      Ah! I think I see your nuance, although I would argue that it is of a somewhat academic character in this case. Isn't "Locates directory of original perl script" in this case similar to Cwd's "get pathname of current working directory"?

      After all, the end results are (on my box) the same. TIMTOWDI, you know ;)

      use FindBin; use Win32; use Cwd; my( $path, $filename ) = Win32::GetFullPathName( $0 ); my $longpath = Win32::GetFullPathName( $path ); print "FindBin: $FindBin::Bin\n"; print "Win32: $longpath\n"; print "Cwd: ", cwd(), "\n";

      The result:

      c:/dev/temp/monks $ perl wdir.pl FindBin: C:/dev/temp/monks Win32: c:\dev\temp\monks\ Cwd: c:/dev/temp/monks

      Seems to me that FindBin and Cwd does more or less the same job here?

      pernod
      --
      Mischief. Mayhem. Soap.

        pernod,
        Notice kamesh3183 said the command prompt and didn't indicate if it was in the same directory. Win32 aside, see the difference:
        $ cat /tmp/foo.pl #!/usr/bin/perl use strict; use warnings; use FindBin; use Cwd; print "FindBin: $FindBin::Bin\n"; print "Cwd: ", cwd(), "\n"; $ ./tmp/foo.pl FindBin: /tmp Cwd: /

        Cheers - L~R

        > Seems to me that FindBin and Cwd does more or less the same job here?

        No

        c:/ $ perl temp/wdir.pl
        FindBin: C:/temp
        Win32:   C:\temp\
        Cwd:     C:/
        c:/ $ 
        
        Whether he should use FindBin or getcwd depends on what he is trying to achieve.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://399184]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2019-08-23 13:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?