Советы по Delphi. Версия 1.4.3 от 1.1.2001
Шрифт:
// Возвращает полный(!) путь типа 'C:\Windows\Рабочий стол\и так далее.lnk',
// 'C:\Program Files\Common Files\Borland Shared\BDE\bdereadme.txt',
// '\\Computer\resource\Folder with long name\File with long name.ext'
//---------------------------------------------------------------------
Function RestoreLongName(fn: string): string;
function LookupLongName(const filename: string): string;
var sr: TSearchRec;
begin
if FindFirst(filename, faAnyFile, sr)=0 then Result:=sr.Name
else Result:=ExtractFileName(filename);
SysUtils.FindClose(sr);
end;
function GetNextFN: string;
var i: integer;
begin
Result:='';
if Pos('\\', fn)=1 then begin
Result:='\\';
fn:=Copy(fn, 3, length(fn)-2);
i:=Pos('\', fn);
if i<>0 then begin
Result:=Result+Copy(fn,1,i);
fn:=Copy(fn, i+1, length(fn)-i);
end;
end;
i:=Pos('\', fn);
if i<>0 then begin
Result:=Result+Copy(fn,1,i-1);
fn:=Copy(fn, i+1, length(fn)-i);
end else begin
Result:=Result+fn;
fn:='';
end;
end;
Var name: string;
Begin
fn:=ExpandFileName(fn);
Result:=GetNextFN;
Repeat
name:=GetNextFN;
Result:=Result+'\'+LookupLongName(Result+'\'+name);
Until length(fn)=0;
End;
Как
Nomadic советует:
procedure FlushIni(FileName: string);
var
{$IFDEF WIN32}
CFileName: array[0..MAX_PATH] of WideChar;
{$ELSE}
CFileName: array[0..127] of Char;
{$ENDIF}
begin
{$IFDEF WIN32}
if (Win32Platform = VER_PLATFORM_WIN32_NT) then begin
WritePrivateProfileStringW(nil, nil, nil, StringToWideChar(FileName, CFileName, MAX_PATH));
end else begin
WritePrivateProfileString(nil, nil, nil, PChar(FileName));
end;
{$ELSE}
WritePrivateProfileString(nil, nil, nil, StrPLCopy(CFileName, FileName, SizeOf(CFileName) – 1));
{$ENDIF}
end;
Копирование
файлов IIINomadic советует:
Можно так:
procedure CopyFile(const FileName, DestName: TFileName);
var
CopyBuffer: Pointer; { buffer for copying }
TimeStamp, BytesCopied: Longint;
Source, Dest: Integer; { handles }
Destination: TFileName; { holder for expanded destination name }
const
ChunkSize: Longint = 8192; { copy in 8K chunks }
begin
Destination := ExpandFileName(DestName); { expand the destination path }
if HasAttr(Destination, faDirectory) then { if destination is a directory... }
Destination := Destination + '\' + ExtractFileName(FileName); { ...clone file name }
TimeStamp := FileAge(FileName); { get source's time stamp }
GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
try
Source := FileOpen(FileName, fmShareDenyWrite); { open source file }
if Source < 0 then raise EFOpenError.Create(FmtLoadStr(SFOpenError, [FileName]));
try
Dest := FileCreate(Destination); { create output file; overwrite existing }
if Dest < 0 then raise EFCreateError.Create(FmtLoadStr(SFCreateError, [Destination]));
try
repeat
Поделиться с друзьями: