Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SHFileOperation Anomaly

Posted on 2001-07-11
2
Medium Priority
?
922 Views
Last Modified: 2007-11-27
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.fAnyOperationsAborted := 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='+SourcePath+' 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 ?
0
Comment
Question by:comicboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 200 total points
ID: 6275843
The pFrom and pTo fields must be double 0 terminated:

opInfo.pFrom := PChar(SourcePath + #0);  //SourceFolder
opInfo.pTo   := PChar(TargetPath + #0);  //DestinationFolder
0
 

Author Comment

by:comicboy
ID: 6289182
Excelent answer :) I don't understand what said in Win32 API about this and you explain it thanks epsylon :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question