Как получить длинное имя файла или каталога, зная короткое имя?
Falk0ner, вс, 06/07/2008 - 15:34.
Взято из http://forum.sources.ru
Автор: P.O.D.
Как получить длинное имя файла или каталога, зная короткое имя?
Используйте Win32_Find_Data поле TSearchRec.
procedure TForm1.Button1Click(Sender: TObject);
var
SearchRec : TSearchRec;
Success : integer;
begin
Success := SysUtils.FindFirst('C:\DownLoad\dial-u~1.htm',
faAnyFile,
SearchRec);
if Success = 0 then begin
ShowMessage(SearchRec.FindData.CFileName);
end;
SysUtils.FindClose(SearchRec);
end;
var
SearchRec : TSearchRec;
Success : integer;
begin
Success := SysUtils.FindFirst('C:\DownLoad\dial-u~1.htm',
faAnyFile,
SearchRec);
if Success = 0 then begin
ShowMessage(SearchRec.FindData.CFileName);
end;
SysUtils.FindClose(SearchRec);
end;
Взято из http://forum.sources.ru
Автор: P.O.D.
unit Unit1;
{©Drkb v.3(2007): www.drkb.ru}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
function GetLongPathNameA(lpszShortPath, lpszLongPath: PChar;
cchBuffer: DWORD): DWORD; stdcall; external kernel32;
var
Form1: TForm1;
implementation
{$R *.dfm}
function ExpandFileName(Path: String): String;
begin
SetLength(Result, MAX_PATH);
if GetLongPathNameA(PChar(Path), @Result[1], MAX_PATH) = 0 then
RaiseLastOSError;
Result := Trim(Result);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
S: String;
begin
// Получаем полное имя
S := ExpandFileName('C:\DOCUME~1\');
ShowMessage(S);
// Получаем урезанное имя
GetShortPathName(PChar(S), PChar(S), MAX_PATH);
ShowMessage(S);
end;
end.
{©Drkb v.3(2007): www.drkb.ru}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
function GetLongPathNameA(lpszShortPath, lpszLongPath: PChar;
cchBuffer: DWORD): DWORD; stdcall; external kernel32;
var
Form1: TForm1;
implementation
{$R *.dfm}
function ExpandFileName(Path: String): String;
begin
SetLength(Result, MAX_PATH);
if GetLongPathNameA(PChar(Path), @Result[1], MAX_PATH) = 0 then
RaiseLastOSError;
Result := Trim(Result);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
S: String;
begin
// Получаем полное имя
S := ExpandFileName('C:\DOCUME~1\');
ShowMessage(S);
// Получаем урезанное имя
GetShortPathName(PChar(S), PChar(S), MAX_PATH);
ShowMessage(S);
end;
end.
Взято из http://forum.sources.ru
Автор: Rouse_
Отправить комментарий