function ShellFileCopy(
const aSource, aDest:
string): Integer;
var
SH: TSHFileOpStructW;
sSource, sDest: WideString;
const
sPrefix: WideString = '
\\?\';
sUNCNewPrefix: WideString = '
\\?\UNC';
sUNCPrefix: WideString = '
\\';
begin
if not StartsText(sUNCPrefix, aSource)
then
sSource := ExpandFileName(aSource);
if not StartsText(sUNCPrefix, aDest)
then
//sDest := ExtractFilePath(ExpandFileName(aDest));
sDest := ExpandFileName(aDest);
if (Length(sSource) >= MAX_PATH)
and not StartsText(sPrefix, sSource)
then
if StartsText(sUNCPrefix, sSource)
then
sSource := sUNCNewPrefix + sSource
else
sSource := sPrefix + sSource;
if (Length(sDest) >= MAX_PATH)
and not StartsText(sPrefix, sDest)
then
if StartsText(sUNCPrefix, sDest)
then
sDest := sUNCNewPrefix + sDest
else
sDest := sPrefix + sDest;
ZeroMemory(@SH, SizeOf(SH));
try
with SH
do
begin
Wnd := 0;
wFunc := FO_COPY;
pFrom := PWideChar(sSource + #0);
pTo := PWideChar(sDest + #0);
fFlags := FOF_ALLOWUNDO
or FOF_NOCONFIRMATION
or FOF_NOCONFIRMMKDIR
or
FOF_SILENT;
end;
Result := SHFileOperationW(SH);
finally
ZeroMemory(@SH, SizeOf(SH));
end;
end;