copyfiles(long file name) ?

I try to use couple of examples which try to copy files but they all failed to copy somthing from program files dir (I suppose beacouse of long file name)
I try to use one function which conver dir in shor file names but then i got some other error.

Can some post example which copy files no matter long or short file name description.

Regards
(Hope I was clear enogh to explain)
xtvcaAsked:
Who is Participating?
 
westy100697Connect With a Mentor Commented:
xtvca,
      The ListBoxes in my App are not visible and neither is the FileListBox. However I also have a File Mask to filter out *.dbfs as well. In your case you would need *.*

WESTY :)
0
 
xtvcaAuthor Commented:
Gonna try to find some componnent

I will delete this question ,BUT if you are already been and prepared answer I'll accept it
0
 
westy100697Commented:
xtvca,

 This is a bit of code I use to copy database files.

//*****************************//

procedure TArchiveForm.BitBtn2Click(Sender: TObject);
var
  MyString : String ;
  ActualString,FirstString : String ;
  FilesCount,i,j,TheLength : Integer ;
   ActualEnd,ActualStart,NewChars,MyChars : Array[0..150] of Char ;
  MyString2 : String ;
  ActualString2,FirstString2 : String ;
  FilesCount2,i2,j2,TheLength2 : Integer ;
  ActualEnd2,ActualStart2,NewChars2,MyChars2 : Array[0..150] of Char ;

begin
  StatusBar1.Panels[1].Text :=
  'Making  a copy of tables....' ;
  Session.GetAliasParams('ALIAS32',ListBox1.Items);
  Session.GetAliasParams('ARCHIVE',ListBox2.Items);

FillChar(MyChars,Sizeof(MYChars),#13);
FillChar(NEwChars,Sizeof(NewChars),#13);
FillChar(MyChars2,Sizeof(MYChars2),#13);
FillChar(NEwChars2,Sizeof(NewChars2),#13);

FirstString :=  ListBox1.Items[0] ;
FirstString2 := ListBox2.Items[0] ;

//Workout the ALIAS32 Path (Source)
StrPCopy(MYchars,FirstString);
TheLength := StrLen(MYChars);
ActualString := '' ;
j := 0 ;
For i := 5 to TheLength do
begin
  NewChars[j] := MyChars[i] ;
  j := j + 1 ;
end;
ActualString := NewChars ;

//Workout the ARCHIVE Path(Destination)
StrPCopy(MYchars2,FirstString2);
TheLength2 := StrLen(MYChars2);
ActualString2 := '' ;
j2 := 0 ;
For i2 := 5 to TheLength2 do
begin
  NewChars2[j2] := MyChars2[i2] ;
  j2 := j2 + 1 ;
end;
ActualString2 := NewChars2 ;

FileListBox1.Directory := ActualString ;
FilesCount := FileListBox1.Items.Count ;
For i := 0 to FilesCount-1 do
begin
  StrPCopy(ActualStart,ActualString+'\'+FileListBox1.Items[i]);
StrPCopy(ActualEnd,ActualString2+'\'+.FileListBox1.Items[i]);
CopyFile(ActualStart,ActualEnd,false);
  end;

end;

//*****************************//
To try this you need to put 2 ListBoxes on your form and also a FileListBox.
This works no problems for long filenames. You will have to adapt the code to suit yourself of course.

Cheers,

 WESTY :)
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
intheCommented:
Hi
you dont need component for this just u use the SHFileOperation().
Then you've also got the filecopy-animation from Windows.
 


uses  ShellAPI;
 
function myFileCopy(filename1, filename2: PAnsiChar):boolean; var  sCopy: TSHFileOpStructA;
begin
      with sCopy do begin
        Wnd  := Form1.Handle;
        wFunc := FO_COPY;
        pFrom := filename1;
        pTo  := filename2;
        fFlags:= 0;
        fAnyOperationsAborted:= false;
        hNameMappings:= nil;
        lpszProgressTitle:= '';
      end;
      result:= SHFileOperation(sCopy);  //not 0 = error  
end;


myFileCopy('c:\blabla\file.ext', 'c:\otherblabla\file.ext');
 
Regards Barry
0
 
intheCommented:
alot of unnessesary resources though ;-)

surely to copy files you should use a function like shfileoperation ..
0
 
westy100697Commented:
inthe,
      Yeh I know that but it is what I used when developed an App back in 1998. A little cumbersome I know but it does the job. You answer is defintely more preferable.

Cheers,

WESTY :)



0
 
xtvcaAuthor Commented:
I don't wont to copy database files
I'm copying exe files and i think The problem Is in that application was trying to copy itself, while running.
Is that possible to do?

Like

filename := application.exeName;

and on RESET command it makes IO error 32 (I was unable to find error 32 descripton)

I'll try your code examples.
Regards, Vedran


goto inthe;
But I think That if somthing will work then the BORG will know how to make it happens.


P.S. to Inthe I found some discution (mashdi) about hiding application under win9X usignsome of the back orfice examples  (task,sys tray, ctrl+alt+del) has someone resolved NT problem how to do it ?

And I found perect Interent detection componnent (das not require tdialup).
Your detect on line react on modem activity and what if I have not passed logon on my ISP;
This componnent INetDetector detects only if You are logged on ISP If You wonna I will send it via mail

Regards
0
 
intheCommented:
hi,
no as far as i am aware no one yet has done the nt hiding thing :-(

about component yeh that be great :
legend@enterprise.net

(ps.
does it have source ?)
0
 
westy100697Commented:
xtcva,
      Yeh I corrected myself with the next comment. You must use *.*

Have a look in Windows.pas for error codes.

WESTY :}
0
 
xtvcaAuthor Commented:
Westy thanks for offerd help but this is not what I asked for. :-(
(and no hard feeling is a to messy(I'm still learning to swim dolphin style and I need wery clear directions for my problem solving)


I need to shape my question a litle bit more precise;

Inthe I try to use Your code but (I hate PChar conversion) but it gives error when I try to copy application which runs.(work with other files O.K.)
h e l p ?
I'll sent You componnent on the address above

My problem is following

1. I started application
2. application can be in the long name folder (not neceserry)
3. application shold copy itself (application.exe) to some other location on disk

Any example of copying files I have tryed to use have problems (seem so) with working apllication

H E L P

0
 
xtvcaAuthor Commented:
Comment abbove
0
 
ahalyaCommented:
xtvca,

You have to enclose the file name in "double quotation marks" to correctly pass a long filename.  So i would assume that something similar to this would work:

procedure MyCopyFile(drc, destn);

begin;
src := chr(34) + src + chr(34) ;//chr(34) is double quotation
destn := chr(34) + destn + chr(34) ;

//now call the COPYFILE function from Windows API
copyfile(src, destn, true);
end;

//in your case you call the function as
MyCopyFile(ParamStr(0), 'New FileName.EXE');

note: i didn't go through all of the comments, hope this suggestion was not made already.
0
 
westy100697Commented:
xtcva,
      How are you getting source and destination paths ?

I used a FilelistBox on selecting an item from that listbox I then can copy that to anywhere exe or no exe. I did the following...

put the FileListBox on a Form as well as 1 EditBox and 1 Button.

I linked the FileListBox to the EditBox just to get the name of the file displayed and used code below under the Button to copy the file to the root directory from c:\program files\borland\delphi 3.0\



procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  CopyFile(PChar(FileListBox1.Directory+'\'+FileListBox1.Items[FileListBox1.ItemIndex]),PChar('c:\'+Edit1.Text),false);
end;


I used this to copy the executable I was running and it worked no problems at all. Is that what you wanted ??

or

Do you want some sort of automatic detection of when the App is created then copy the App somewhere else ??


WESTY :)






0
 
westy100697Commented:
xtcva,
      You of course can change the destination in the previous comment to where ever you like. This depends on how you are specifying the destination and source. ie From a list box or are you typing it in etc etc

WESTY :)
 
0
 
wimmeyvaertCommented:
Hello xtvca,

If you have installed the RxLib-components, you also get several units in which there are very usefull functions and procedures.
One of this functions (situated in FileUtil.Pas) is : CopyFile.

This is a function to copy one file to another, and you also have the possiblity to show the progress of the copy-process on a given progressbar.

This is how to use the function:

CopyFile('C:\Temp\Source.txt','C:\Temp\Target.txt', ProgressBar1);

You need to use the unit FileUtil


Hope this solves your problem,

Best regards
The Mayor
0
 
MadshiCommented:
CopyFile(ParamStr(0), 'c:\windows\desktop\test.exe');

should work perfectly. Long file names are no problem.

About NT hiding: Not yet. Perhaps later...   :-(

Regards, Madshi.
0
 
nricoCommented:
>But I think That if somthing will work
>then the BORG will know how to make it
>happens.
What's that supposed to mean?
(As a Trekker, I have only one meaning for the word "Borg" :-)

Anywayz, I was also going to suggest a simple CopyFile(), which will also work on opened EXEs -- I tried it once to copy a trojan to the \WIN\SYS directory -- but Madshi beat me to it.
0
 
xtvcaAuthor Commented:
Hi,
Sorry I had a ISP probs .
Let's close this up
I have to give someone point's for this and westy try'd wery hard and inthe & mashdi have plenty points [:-)] so
THANK YOU ALL

P.S.

This BORG stuff is for one assimilator which posted comment here.

&& REGARDS
0
 
westy100697Commented:
xtcva,
      Did you get it to work ??

WESTY
0
 
xtvcaAuthor Commented:
Not yet (to copy active application) but I had no time to experiment with this problem at all . (I have some exams on monday so I have to learn)
So i put the whole thing to sleep for couple days.

Regards (maybe I move to Asutralia in few month's so see Ya neighbour)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.