文件拷贝问题(20分)

  • 主题发起人 主题发起人 mythad
  • 开始时间 开始时间
M

mythad

Unregistered / Unconfirmed
GUEST, unregistred user!
var
ichar:pAnsiChar;
begin
ichar := PAnsiChar(path);
shellinfo.wnd:=handle;
shellinfo.wFunc:=FO_COPY;
shellinfo.pFrom:= ichar;
shellinfo.pTo:='E:/xk1';
其中path是string型的,在赋pFrom的时候ichar的值为空了,没赋值之前还正常,怎么回事?我用Pchar()转换也不行,这到底什么问题?急等..
 
你这个没有用过,
给你贴一段小代码。关于文件拷贝。
procedure FileCopy(const sourcefilename,targetfilename:string);
var
S,T:TFileStream;
begin
S:=TFileStream.Create(sourcefilename,fmOpenRead);
try
T:=TFileStream.Create(targetfilename,
fmOpenWrite or fmCreate);
try
T.CopyFrom(S,S.Size);
finally
T.Free;
end;
finally
S.Free;
end;
end;
 
var
ichar:pAnsiChar;
ShellInfo: TSHFileOpStructA;
path:string;
begin
path:='c:/1.jpg';
ichar := PAnsiChar(path);
shellinfo.wnd:=handle;
shellinfo.wFunc:=FO_COPY;
shellinfo.pTo:='D:/xk1.jpg';
shellinfo.pFrom:= ichar;
SHFileOperation(ShellInfo);
 
The CopyFile function copies an existing file to a new file.
BOOL CopyFile(
LPCTSTR lpExistingFileName, // pointer to name of an existing file
LPCTSTR lpNewFileName, // pointer to filename to copy to
BOOL bFailIfExists // flag for operation if file exists
);
Parameters
lpExistingFileName
Points to a null-terminated string that specifies the name of an existing file.
lpNewFileName
Points to a null-terminated string that specifies the name of the new file.
bFailIfExists
Specifies how this operation is to proceed if a file of the same name as
that specified by lpNewFileName already exists. If this parameter is TRUE and
the new file already exists, the function fails. If this parameter is FALSE
and the new file already exists, the function overwrites the existing file and
succeeds.
 
非常感谢各位,结帖送分.
 
多人接受答案了。
 
后退
顶部