T
toniry
Unregistered / Unconfirmed
GUEST, unregistred user!
我在做文件夹内容复制的时候,发现当源文件夹的长度字符串(如c:/aaa/bbb/)超过一定长度时(比如45个字符),运行复制就提示“无法复制文件:无法读取源文件或磁盘”的错误。估计是在字符串转换成pchar类型时发生问题。
用如下的写法对于有的复制文件夹函数(我在网上找到的函数)没问题,有的程序段有出现上述提示:
PChar('C:/Documents and Settings/new/Local Settings/Application Data/Identities/{7238B769-F427-4DDE-BFCE-2B9BFCA21BE7}/Microsoft/Outlook Express');
对于上面没问题的函数,当把中间的变量换成字符串相加是,还是会出现错误提示。
PChar('C:/Documents and Settings/'+UserName+'/Local Settings/Application Data/Identities/'+UserID+'/Microsoft/Outlook Express');
整个函数如下,朋友们帮我看看。估计是在字符串转换成pchar类型时发生问题,但不知怎么解决:
procedure TForm1.BackupFile;
var
sPath,tPath:string;
fsTemp:SHFILEOPSTRUCT;
i:integer;
begin
sPath := 'c:/bu';
//tPath := 'C:/Documents and Settings/'+UserName+'/Local Settings/Application Data/Identities/'+UserID+'/Microsoft/Outlook Express' ;
//tPath := 'C:/Documents and Settings/'+UserName+'/Local Settings/Application Data/Adobe/Color' ;
if sPath <> '' then
begin
fsTemp.Wnd := Self.Handle;
//设置文件操作类型
fsTemp.wFunc := FO_COPY;
//源文件全路径名
//fsTemp.pFrom := PChar('C:/Documents and Settings/new/Local Settings/Application Data/Identities/{7238B769-F427-4DDE-BFCE-2B9BFCA21BE7}/Microsoft/Outlook Express');
fsTemp.pFrom := PChar('C:/'+UserID+'/'+UserName+'aaaaaaaaaa') ;
//要移动到的路径
fsTemp.pTo := PChar(sPath);
if SHFileOperation(fsTemp) <> 0 then
Edit2.text := 'C:/'+UserID+'/'+UserName+'aaaaaaaaaa';
end;
end;
用如下的写法对于有的复制文件夹函数(我在网上找到的函数)没问题,有的程序段有出现上述提示:
PChar('C:/Documents and Settings/new/Local Settings/Application Data/Identities/{7238B769-F427-4DDE-BFCE-2B9BFCA21BE7}/Microsoft/Outlook Express');
对于上面没问题的函数,当把中间的变量换成字符串相加是,还是会出现错误提示。
PChar('C:/Documents and Settings/'+UserName+'/Local Settings/Application Data/Identities/'+UserID+'/Microsoft/Outlook Express');
整个函数如下,朋友们帮我看看。估计是在字符串转换成pchar类型时发生问题,但不知怎么解决:
procedure TForm1.BackupFile;
var
sPath,tPath:string;
fsTemp:SHFILEOPSTRUCT;
i:integer;
begin
sPath := 'c:/bu';
//tPath := 'C:/Documents and Settings/'+UserName+'/Local Settings/Application Data/Identities/'+UserID+'/Microsoft/Outlook Express' ;
//tPath := 'C:/Documents and Settings/'+UserName+'/Local Settings/Application Data/Adobe/Color' ;
if sPath <> '' then
begin
fsTemp.Wnd := Self.Handle;
//设置文件操作类型
fsTemp.wFunc := FO_COPY;
//源文件全路径名
//fsTemp.pFrom := PChar('C:/Documents and Settings/new/Local Settings/Application Data/Identities/{7238B769-F427-4DDE-BFCE-2B9BFCA21BE7}/Microsoft/Outlook Express');
fsTemp.pFrom := PChar('C:/'+UserID+'/'+UserName+'aaaaaaaaaa') ;
//要移动到的路径
fsTemp.pTo := PChar(sPath);
if SHFileOperation(fsTemp) <> 0 then
Edit2.text := 'C:/'+UserID+'/'+UserName+'aaaaaaaaaa';
end;
end;