Delphi Programming

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

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

By Zarko Gajic, About.com

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

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Delphi Programming

  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.