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

Hello Perl monks

I need help with the Win32::GetShortPathName. On one problem machine, the function does not always return a short (8.3) path name. The machine is Windows 2000 running ActiveState 5.6.1 build 635.

My test code is:

#-- test perl program to determine set up use strict; use warnings; print "\n\nTest program to determine OS/File paths as seen by Perl \n\ +n"; #-- get the OS variable print "\nOperating system as returned by \$^O variable is:\t $^O\n"; #-- list of directories my @files = ( 'C:\program files\merant build', 'C:\PROGRA~1\merant build' ); foreach my $file ( @files ) { print "Long Path:\t$file\nShortPath:\t" . Win32::GetShortPathName($file) . "\n\n"; }
The result of the test is:

Test program to determine OS/File paths as seen by Perl Operating system as returned by $^O variable is: MSWin32 Long Path: C:\program files\merant build ShortPath: C:\PROGRA~1\merant build Long Path: C:\PROGRA~1\merant build ShortPath: C:\PROGRA~1\merant build
I was expecting "C:\PROGRA~1\MERANT~1" in both cases. On other machines with the same directory structure, "C:\PROGRA~1\MERANT~1" is returned. Is there anywhere I should look on the machine itself (a system dll?) to see why this may be occurring? Thanks in advance.

Replies are listed 'Best First'.
Re: Win32::GetShortPath doesn't always return an 8.3 short Path?
by esskar (Deacon) on Mar 04, 2004 at 18:43 UTC
    does "C:\program files\merant build" really exists? windows has to lookup the shortname in the filesystem directly; and if the path does not exists, it can't look it up!
Re: Win32::GetShortPath doesn't always return an 8.3 short Path? (specific?)
by tye (Sage) on Mar 04, 2004 at 18:38 UTC

    I suspect the problem is specific to that directory. I'd repair the file system and/or rename the directory then rename it back.

    - tye        

Re: Win32::GetShortPath doesn't always return an 8.3 short Path?
by maa (Pilgrim) on Mar 04, 2004 at 19:28 UTC
    Perhaps the module thinks that it's already a short name as you used the C:\Progra~1\ in your test... a reliable (if _bad_) way would be to issue a my $dir=system("cmd /c dir /x $file"); and then pattern match to capture the bit you wanted?
      Hi,

      Thanks for the responses. The directory does exist. The "problem" is one with the filesystem. Turns out, if you set a Windows Registry key
      HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\FileSystem\NtfsDis +able8dot3NameCreation
      the filesystem will not allow a short file name to be aliased to the long file. The sysadmins on the machine had set this key for security purposes. I assume that the GetShortPath routine calls the system dll, assuming the "short" value returned is in 8.3 format, although it's now not guarenteed to be. So it's not a Perl problem per se, although the Perl doc is not absolutely correct.

      Again, thanks for the responses.