comicboy
asked on
SHFileOperation Anomaly
I create the code below for simplify copy across drives. It's ok if I run the program from harddisk, but when I burn it to CD-ROM or run this copy program from Diskette, it said "cannot copy file: file system error (1026)".
procedure FileOperation(Handle: HWND;
SourcePath, TargetPath: string;
Operation: byte);
var
opInfo : _SHFILEOPSTRUCT;
begin
opInfo.pFrom := PChar(SourcePath); //SourceFolder
opInfo.pTo := PChar(TargetPath); //DestinationFolder
case Operation of
1: begin
opInfo.wFunc := FO_MOVE;
opInfo.lpszProgressTitle := 'Moving . . .';
end;
2: begin
opInfo.wFunc := FO_COPY;
opInfo.lpszProgressTitle := 'Copying . . .';
end;
3: begin
opInfo.wFunc := FO_DELETE;
opInfo.lpszProgressTitle := 'Deleting . . .';
end;
4: begin
opInfo.wFunc := FO_RENAME;
opInfo.lpszProgressTitle := 'Renaming . . .';
end;
end;
opInfo.fFlags := FOF_NOCONFIRMATION or //no confirmation
FOF_NOCONFIRMMKDIR or //no confirmation
FOF_FILESONLY or //Only files effected and must use wildcard *.*
FOF_SIMPLEPROGRESS; //show a progress
opInfo.hNameMappings := nil; // no mappings
opInfo.fAnyOperationsAbort ed := False; //obsolete
opInfo.Wnd := Handle; //the parent of the progressdisplay
SHFileOperation(opInfo);
end;
The strange also happen when I simply add this code simply to show wether the sourcepath and targetpath is ok :
ShowMessage('source='+Sour cePath+' target='+TargetPath);
It cause the same 1026 error even I run the program from harddisk and copy from diskette a:\*.* to a folder in harddisk c:\test\
also the other strange thing is when I do this program from CD-ROM and got error 1026 and do it again, it run ok, it copy files from folder in my CD-ROM to a folder on my harddisk.
Can experts help me fix this ?
procedure FileOperation(Handle: HWND;
SourcePath, TargetPath: string;
Operation: byte);
var
opInfo : _SHFILEOPSTRUCT;
begin
opInfo.pFrom := PChar(SourcePath); //SourceFolder
opInfo.pTo := PChar(TargetPath); //DestinationFolder
case Operation of
1: begin
opInfo.wFunc := FO_MOVE;
opInfo.lpszProgressTitle := 'Moving . . .';
end;
2: begin
opInfo.wFunc := FO_COPY;
opInfo.lpszProgressTitle := 'Copying . . .';
end;
3: begin
opInfo.wFunc := FO_DELETE;
opInfo.lpszProgressTitle := 'Deleting . . .';
end;
4: begin
opInfo.wFunc := FO_RENAME;
opInfo.lpszProgressTitle := 'Renaming . . .';
end;
end;
opInfo.fFlags := FOF_NOCONFIRMATION or //no confirmation
FOF_NOCONFIRMMKDIR or //no confirmation
FOF_FILESONLY or //Only files effected and must use wildcard *.*
FOF_SIMPLEPROGRESS; //show a progress
opInfo.hNameMappings := nil; // no mappings
opInfo.fAnyOperationsAbort
opInfo.Wnd := Handle; //the parent of the progressdisplay
SHFileOperation(opInfo);
end;
The strange also happen when I simply add this code simply to show wether the sourcepath and targetpath is ok :
ShowMessage('source='+Sour
It cause the same 1026 error even I run the program from harddisk and copy from diskette a:\*.* to a folder in harddisk c:\test\
also the other strange thing is when I do this program from CD-ROM and got error 1026 and do it again, it run ok, it copy files from folder in my CD-ROM to a folder on my harddisk.
Can experts help me fix this ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER