in reply to Re: Current working directory on win32
in thread Current working directory on win32

> 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

  • Comment on Re^2: Current working directory on win32

Replies are listed 'Best First'.
Re^3: Current working directory on win32
by pernod (Chaplain) on Oct 14, 2004 at 13:31 UTC

    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.