NAME

Win32::LFN - Long File Names, paths and file attributes on Win32


SYNOPSIS

 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


ABSTRACT

This module provides subroutines to convert full or relative short (8.3) or long or mixed file paths to relative or absolute paths in версия для печати LFN form.

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/


DESCRIPTION

This module is a collection of subroutines. All of them are exported by default. Don't like this? You can 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().

GetFullPathName ( FILENAME )
GetFullPathName combines the FILENAME with the current drive and directory name and returns a fully qualified (aka, absolute) path name. Note that no attempt is made to convert 8.3 components in the supplied FILENAME to longnames or vice-versa.

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.

GetLongPathName ( FILENAME )
Returns a representaion of FILENAME comprised of longname compnents (if any). The result may not necessarily be longer than FILENAME. No attempt is made to convert FILENAME to the absolute path.

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.

GetFullLFN ( FILENAME )
This function gives absolute path with all elements converted to LFN, backslash separated.

GetPathLFN ( FILENAME )
A alias to GetFullPathName() for compartibility with the older versions.

GetAttributesLFN ( FILENAME )
This function returns the array of numbers 1-18 that are file/dir attributes and are described very poorly in the 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.


INSTALLATION

As this is just a plain module no special installation is needed. Just put it into the Win32 subdirectory somewhere in your @INC.

This module requires Win32::API module by Aldo Calpini.


CAVEATS

This module has been created and tested in a Win95 environment. Although I expect it to function correctly on Windows NT, that fact has been only briefly confirmed.


CHANGES

 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".


BUGS

Please report.


VERSION

This man page documents ``Win32::LFN'' version 0.05.

July 6, 1999.


AUTHOR

Mike Blazer, blazer@mail.nevalink.ru


SEE ALSO

perl(1)


COPYRIGHT

Copyright (C) 1999 Mike Blazer.

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.