oteau
asked on
SHFileOperation truncate filename
Hello all,
Is-it normal that SHFileOperation truncate filename when I use it to copy a directory and all his content ?
Ex. : Transactions.DB => Transact.DB
TempTransac.DB => TempTran.DB
This is the procedure I use to copy the files :
procedure WorkOnFiles(Sender : TForm; xFrom, xTo, xProc : String);
var
FPath : String;
fileOp: TShFileOpStruct;
fromDir, toDir : Array[0..1000] of Char;
Proc : UINT;
begin
FPath := ExtractFilePath(Applicatio n.ExeName) ;
FillChar(fileOp,SizeOf(fil eOp),#0);
FillChar(fromDir,SizeOf(fr omDir),#0) ;
FillChar(toDir,SizeOf(toDi r),#0);
StrPCopy(fromDir,xFrom);
StrPCopy(toDir,xTo);
Proc := FO_COPY;
if xProc = 'FO_DELETE' then
Proc := FO_DELETE
else
if xProc = 'FO_COPY' then
Proc := FO_COPY
else
if xProc = 'FO_MOVE' then
Proc := FO_MOVE
else
if xProc = 'FO_RENAME' then
Proc := FO_RENAME;
with fileOp do begin
wnd := Sender.Handle;
wfunc := Proc;
pFrom := @fromDir;
pTo := @toDir;
fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR;
fAnyOperationsAborted := false;
hNameMappings := nil;
lpszProgressTitle := nil;
end;
SHFileOperation(fileOp);
end;
And here is how I call my procedure :
WorkOnFiles(Self, 'G:\GescomWin\Data\*.*', 'G:\GescomWin\Backup Data\', 'FO_COPY');
Help needed !
Thanks in advance
Oteau
Is-it normal that SHFileOperation truncate filename when I use it to copy a directory and all his content ?
Ex. : Transactions.DB => Transact.DB
TempTransac.DB => TempTran.DB
This is the procedure I use to copy the files :
procedure WorkOnFiles(Sender : TForm; xFrom, xTo, xProc : String);
var
FPath : String;
fileOp: TShFileOpStruct;
fromDir, toDir : Array[0..1000] of Char;
Proc : UINT;
begin
FPath := ExtractFilePath(Applicatio
FillChar(fileOp,SizeOf(fil
FillChar(fromDir,SizeOf(fr
FillChar(toDir,SizeOf(toDi
StrPCopy(fromDir,xFrom);
StrPCopy(toDir,xTo);
Proc := FO_COPY;
if xProc = 'FO_DELETE' then
Proc := FO_DELETE
else
if xProc = 'FO_COPY' then
Proc := FO_COPY
else
if xProc = 'FO_MOVE' then
Proc := FO_MOVE
else
if xProc = 'FO_RENAME' then
Proc := FO_RENAME;
with fileOp do begin
wnd := Sender.Handle;
wfunc := Proc;
pFrom := @fromDir;
pTo := @toDir;
fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR;
fAnyOperationsAborted := false;
hNameMappings := nil;
lpszProgressTitle := nil;
end;
SHFileOperation(fileOp);
end;
And here is how I call my procedure :
WorkOnFiles(Self, 'G:\GescomWin\Data\*.*', 'G:\GescomWin\Backup Data\', 'FO_COPY');
Help needed !
Thanks in advance
Oteau
it seems like you code is OK, here's my version that does not truncate filenames
procedure TForm1.sbut_CopyFilesClick (Sender: TObject);
function CopyIt(Sender : TForm; sFrom, sTo: String; Opp:Integer):Boolean;
const
ksTitle = 'The Title';
var
shFileOpRec : TSHFileOpStruct ;
begin
sFrom := sFrom+#0;
with shFileOpRec do
begin
Wnd := Sender.Handle ;
wFunc := Opp;
pFrom := PAnsiChar(sFrom) ;
pTo := PAnsiChar(sTo) ;
fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR;
hNameMappings:= nil;
fAnyOperationsAborted:= false;
lpszProgressTitle:= ksTitle;
end;
if (SHFileOperation (shFileOpRec) = 0 ) then result:=True else result := False;
if ( shFileOpRec.fAnyOperations Aborted = true ) then
begin
Result := False;
MessageBox(Sender.Handle,' Copy CANCELED',
'Copy CANCELED',MB_OK or MB_ICONERROR);
end;
end;
begin
CopyIt(Form1, 'C:\Stuff\*.*', 'E:\Temp Back', FO_COPY)
end;
- - - - - - - - - - - - -
I don't think including
hNameMappings := nil;
will make a difference? But this works for me on win9x
procedure TForm1.sbut_CopyFilesClick
function CopyIt(Sender : TForm; sFrom, sTo: String; Opp:Integer):Boolean;
const
ksTitle = 'The Title';
var
shFileOpRec : TSHFileOpStruct ;
begin
sFrom := sFrom+#0;
with shFileOpRec do
begin
Wnd := Sender.Handle ;
wFunc := Opp;
pFrom := PAnsiChar(sFrom) ;
pTo := PAnsiChar(sTo) ;
fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR;
hNameMappings:= nil;
fAnyOperationsAborted:= false;
lpszProgressTitle:= ksTitle;
end;
if (SHFileOperation (shFileOpRec) = 0 ) then result:=True else result := False;
if ( shFileOpRec.fAnyOperations
begin
Result := False;
MessageBox(Sender.Handle,'
'Copy CANCELED',MB_OK or MB_ICONERROR);
end;
end;
begin
CopyIt(Form1, 'C:\Stuff\*.*', 'E:\Temp Back', FO_COPY)
end;
- - - - - - - - - - - - -
I don't think including
hNameMappings := nil;
will make a difference? But this works for me on win9x
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'll try all of your version. Thanks a lot.
I run my prog on winnt4 sp6a.
I'll give you news as soon as possible.
Thanks again.
I run my prog on winnt4 sp6a.
I'll give you news as soon as possible.
Thanks again.
ASKER
Another thing : I run those program from a network share.
My server run on Terminal Server.
Does the network drive can cause this problem ??
My server run on Terminal Server.
Does the network drive can cause this problem ??
Some network OS systems shorten file names. I have heard of Novell doing this.
ASKER
I have tried all of your versions, but nothing work. I'm going to test it locally.
I really don't understand....
I really don't understand....
Someone may have said this already but try it on a local (non-network) drive. I think it's your network OS causing this problem.
ASKER
Something really strange is happening :
On test machine, the program truncate filename. But, on client side, all of my instance works perfectly !!!! I have the same configuration on both side, except for service pack (On my machine : sp6a Client : sp4). Is the service pack the reason why it's not working in my developpement environement ????
For the moment, I have no idea. But it works in production. So, I will check later on my netwotk. Project must go on !!!!
Thanks all for your comment.
Oteau
On test machine, the program truncate filename. But, on client side, all of my instance works perfectly !!!! I have the same configuration on both side, except for service pack (On my machine : sp6a Client : sp4). Is the service pack the reason why it's not working in my developpement environement ????
For the moment, I have no idea. But it works in production. So, I will check later on my netwotk. Project must go on !!!!
Thanks all for your comment.
Oteau
Maybe. Most likely your network client software version is the reason for this.
this seems a win9* problem as its fine on nt/2000.
try it like this:
uses shellapi;
procedure WorkOnFiles(Sender : TForm; xFrom, xTo, xProc : String);
var
FPath : String;
fileOp: TShFileOpStruct;
fromDir, toDir : string;
Proc : UINT;
begin
FPath := ExtractFilePath(Applicatio
FillChar(fileOp,SizeOf(fil
fromdir := xFrom + #0;
toDir := xTo + #0;
if xProc = 'FO_DELETE' then
Proc := FO_DELETE
else
if xProc = 'FO_COPY' then
Proc := FO_COPY
else
if xProc = 'FO_MOVE' then
Proc := FO_MOVE
else
if xProc = 'FO_RENAME' then
Proc := FO_RENAME;
with fileOp do begin
wnd := Sender.Handle;
wfunc := Proc;
pFrom := pchar(fromDir);
pTo := pchar(toDir);
fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR;
fAnyOperationsAborted := false;
end;
SHFileOperation(fileOp);
end;
procedure TForm1.Button1Click(Sender
begin
WorkOnFiles(Self, 'D:\cvs\*.*', 'D:\CVSBACKUP\', 'FO_COPY');
end;
Regards Barry
ps,
what operating system are you testing this on?