File Shell Operations
Posted on 2001-07-27
Hi, I'm trying to use the
SHFileOperation function (in unit ShellAPI).
What I want to accomplish is:
1) SHMoveFile(SourceFile, TargetFile: String): Boolean;
2) SHCopyFile(SourceFile, TargetFile: String): Boolean;
This is my current code:
-------- BEGIN CODE SNIPPET ------------
function SHOper(Operator: Cardinal; const SourceFile, TargetFile: String): Boolean;
with Info do begin
Wnd := frmSort.Handle;
wFunc := Operator;
pFrom := PChar(SourceFile);
pTo := PChar(TargetFile);
fFlags := FOF_ALLOWUNDO;
Result := (SHFileOperation(Info) = 0);
function SHCopyFile(const SourceFile, TargetFile: string): Boolean;
Result := SHOper(FO_COPY, SourceFile, TargetFile);
function SHMoveFile(const SourceFile, TargetFile: string): Boolean;
Result := SHOper(FO_MOVE, SourceFile, TargetFile);
-------- END CODE SNIPPET ------------
And, it works SOMETIMES!?!? ...I get the error:
An error occured in the filesystem (error no 1026),
but ONLY on some files (it seems almost random??).
I don't have any faulty disks/filesystems; it's the
same on all machines i've tried; and I can copy
the file in Windows Explorer, which i assume use the
very same function.
The CopyFile(); and MoveFile(); of Windows unit seems
to work perfect, on ALL files. But I need the l33t
progressbar and so on..
So what am I doing wrong?
I simply call my procedures like:
I know the destination directory already exist (i did a ForceDirectories before the call).
What might be wrong? Please help me :]