use Win32::LFN;
$short = '..\Persis~2\..\\';
$abs = GetFullPathName($short) or Win32::GetLastError and die Win32::FormatMessage(Win32::GetLastError); $long = GetLongPathName($short) or Win32::GetLastError and die Win32::FormatMessage(Win32::GetLastError); $full = GetFullLFN($short) or Win32::GetLastError and die Win32::FormatMessage(Win32::GetLastError); @attr = GetAttributesLFN($short);
print <<E_O_PRNT; SHORT : $short LONG : $long ABS PATH : $abs FULL-PATH: $full ATTR : @attr E_O_PRNT
Now there are the appropriate built-ins in the current ActiveState port and in upcoming Perl 5.006, so this module is for those who stuck with old perl releases. .
The current version of Win32::LFN is available at:
http://www.dux.ru/guest/fno/perl/
require it instead of use.
The
FAT file system and
NTFS support filenames up to 255 characters long. This is known as a long filename or ``screen name''. To get an
MS-DOS filename given a long filename, use the
Win32::GetShortPathName()
built-in function. Note that because of the bug in Perl earlier then
5.004_04 you should parse the result through
s/\0.*$//
to strip the rest of the buffer.
NOTE: FILENAME in the following description is a path of an existing file or directory (UNC paths also) in either full or relative form with short or long (LFN) tokens with both forward and backward slashes. Whatever mixtures of \.\ and \..\ and \...\ and more dots are OK. (For example \.... means \..\..\..)
C:file.txt-style notation (which means ``file.txt in the current directory of the drive C:``) is
OK in this version of the module.
"C:" is also not an error any more, it points to the current directory of the
drive C:.
So,
FILENAME has to be an existing path from Windows point
of view, while -e FILENAME may return
FALSE.
Samples:
'file~5.t' './file~2.txt' '.\FILE~1.php' 'c:\perl-samples\CURREN~2' 'lib/File~1.p' 'lib\FILE~1.php' "\\\\server\\x\\dir1\\FILE~1" '../_mylib~2/file.txt' etc. etc.
All subroutines return undef on errors. You can trap and print errors with Win32::GetLastError() and Win32::FormatMessage().
The same as Win32::GetFullPathName() built-in function in Perl 5.006 and ActiveState port as of build 514.
The result is always backslash separated.
The same as Win32::GetLongPathName() built-in function in Perl 5.006 and ActiveState port as of build 514.
If at least one slash in FILENAME is backslash the result is backslash separated, othewise - forward slash separated.
Win32SDK docs.
This is an excerpt from the Win32\shlobj.h file (a number on the left is what you will have in the @attrs array):
1 SFGAO_CANRENAME # Objects can be renamed 2 SFGAO_CANDELETE # Objects can be deleted 3 SFGAO_HASPROPSHEET # Objects have property sheets 4 SFGAO_DROPTARGET # Objects are drop target 5 SFGAO_CAPABILITYMASK # 6 SFGAO_LINK # Shortcut (link) 7 SFGAO_SHARE # shared 8 SFGAO_READONLY # read-only 9 SFGAO_GHOSTED # ghosted icon 10 SFGAO_DISPLAYATTRMASK # 11 SFGAO_FILESYSANCESTOR # It contains file system folder 12 SFGAO_FOLDER # It's a folder. 13 SFGAO_FILESYSTEM # is a file system thing (file/folder/root) 14 SFGAO_HASSUBFOLDER # Expandable in the map pane 15 SFGAO_CONTENTSMASK # 16 SFGAO_VALIDATE # invalidate cached information 17 SFGAO_REMOVABLE # is this removeable media? 18 SFGAO_COMPRESSED # Object is compressed (use alt color)
Some of those attributes like 6, 7, 17 might be useful, some other are usual attributes or might be checked by Perl itself.
This module requires Win32::API module by Aldo Calpini.
0.04 Completely rewritten with the same interface. Few bugs fixed.
POD documents added. Functions peforms faster now.
0.05 I hope the last release ;-)
LFN algorithm is completely rewritten.
Two functions added that mimic Win32::GetFullPathName and
Win32::GetLongPathName built in functions and use much faster
FindFirstFile API call.
GetFileLFN() function is removed because GetFullLFN() is now
very fast.
$Win32::LFN::SHORT_SEPARATOR is no longer used because the new
algorithm always returns the correct "screen name".
July 6, 1999.
perl(1)
This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.