1. Home
  2. Computing & Technology
  3. Delphi Programming

From/to the 8.3 (short) format to/from the long format

By , About.com Guide

This unit provides two functions that convert filenames from the long format to the 8.3 format, and from the 8.3 format to the long format.

~~~~~~~~~~~~~~~~~~~~~~~~~
unit LFN_ALT;
interface
function AlternateToLFN(AltName:String):String;
function LFNToAlternate(LongName:String):String;

implementation

uses Windows;

function AlternateToLFN(AltName:String):String;
var
  temp: TWIN32FindData;
  searchHandle: THandle;
begin
  searchHandle:=FindFirstFile(PChar(AltName),temp) ;
  if searchHandle <> ERROR_INVALID_HANDLE then
    result := String(temp.cFileName)
  else
    result := '';
  Windows.FindClose(searchHandle) ;
end;

function LFNToAlternate(LongName:String):String;
var
  temp: TWIN32FindData;
  searchHandle: THandle;
begin
  searchHandle:=FindFirstFile(PChar(LongName),temp) ;
  if searchHandle <> ERROR_INVALID_HANDLE then
    result := String(temp.cALternateFileName)
  else
    result := '';
  Windows.FindClose(searchHandle) ;
end;
end.{unit}

~~~~~~~~~~~~~~~~~~~~~~~~~
ps. If you have Delphi 6+, you can use the ExtractShortPathName RTL function.

Delphi tips navigator:
» Get File 'Last Modified' attribute
« Delete folders recursively

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 1999 Delphi Tips
  7. From/to the 8.3 (short) format to/from the long format

©2009 About.com, a part of The New York Times Company.

All rights reserved.