Solved

SHFileOperation truncate filename

Posted on 2002-05-13
10
938 Views
Last Modified: 2010-05-18
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(Application.ExeName);
  FillChar(fileOp,SizeOf(fileOp),#0);
  FillChar(fromDir,SizeOf(fromDir),#0);
  FillChar(toDir,SizeOf(toDir),#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
0
Comment
Question by:oteau
[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
10 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 7007226
hi,
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(Application.ExeName);
 FillChar(fileOp,SizeOf(fileOp),#0);
 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: TObject);
begin
WorkOnFiles(Self, 'D:\cvs\*.*', 'D:\CVSBACKUP\', 'FO_COPY');
end;


Regards Barry

ps,
what operating system are you testing this on?
0
 
LVL 34

Expert Comment

by:Slick812
ID: 7007332
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.fAnyOperationsAborted = 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
0
 
LVL 2

Accepted Solution

by:
mikepj earned 150 total points
ID: 7007414
I now see others have also provided new versions but I wanted to see SHFileOperation for myself also.  No file name truncation here (NT4).

type
  TWorkType=(wofCopy,wofDelete,wofMove,wofRename);

procedure WorkOnFiles(Sender : TForm; xFrom, xTo:string; optype:TWorkType);
var
 fileOp:  TShFileOpStruct;
 iProc : UINT;
begin
  case optype of
    wofCopy:iProc:=FO_COPY;
    wofDelete:iProc:=FO_DELETE;
    wofMove:iProc:=FO_MOVE;
    wofRename:iProc:=FO_RENAME;
    else Raise Exception.Create('Unhandled operation');
    end;

 with fileOp do begin
   wnd     := Sender.Handle;
   wfunc   := iProc;
   pFrom   := PChar(xFrom);
   pTo     := PChar(xTo);
   fFlags  := FOF_ALLOWUNDO or FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR;
   fAnyOperationsAborted := false;
   hNameMappings         := nil;
   lpszProgressTitle     := nil;
 end;

 SHFileOperation(fileOp);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  WorkOnFiles(self,'c:\tmp\t3\*.*','d:\tmp\t3',wofCopy);
end;

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:oteau
ID: 7008420
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.
0
 

Author Comment

by:oteau
ID: 7008427
Another thing : I run those program from a network share.
My server run on Terminal Server.

Does the network drive can cause this problem ??
0
 
LVL 2

Expert Comment

by:mikepj
ID: 7008773
Some network OS systems shorten file names.  I have heard of Novell doing this.
0
 

Author Comment

by:oteau
ID: 7031988
I have tried all of your versions, but nothing work. I'm going to test it locally.

I really don't understand....
0
 
LVL 2

Expert Comment

by:mikepj
ID: 7032145
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.
0
 

Author Comment

by:oteau
ID: 7037232
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
0
 
LVL 2

Expert Comment

by:mikepj
ID: 7037269
Maybe.  Most likely your network client software version is the reason for this.

0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 127
Working with hours 3 74
Reconfigure Delphi Install? 2 65
control image tags in a string ? 12 154
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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