Solved

copyfiles(long file name) ?

Posted on 2000-03-20
20
283 Views
Last Modified: 2010-04-04
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)
0
Comment
Question by:xtvca
  • 7
  • 6
  • 3
  • +4
20 Comments
 

Author Comment

by:xtvca
ID: 2637767
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
 

Expert Comment

by:westy100697
ID: 2637857
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
 
LVL 17

Expert Comment

by:inthe
ID: 2637858
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
 

Accepted Solution

by:
westy100697 earned 50 total points
ID: 2637864
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
 
LVL 17

Expert Comment

by:inthe
ID: 2638037
alot of unnessesary resources though ;-)

surely to copy files you should use a function like shfileoperation ..
0
 

Expert Comment

by:westy100697
ID: 2638048
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
 

Author Comment

by:xtvca
ID: 2638108
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
 
LVL 17

Expert Comment

by:inthe
ID: 2638160
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
 

Expert Comment

by:westy100697
ID: 2638162
xtcva,
      Yeh I corrected myself with the next comment. You must use *.*

Have a look in Windows.pas for error codes.

WESTY :}
0
 

Author Comment

by:xtvca
ID: 2638189
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:xtvca
ID: 2638192
Comment abbove
0
 
LVL 7

Expert Comment

by:ahalya
ID: 2638411
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
 

Expert Comment

by:westy100697
ID: 2638526
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
 

Expert Comment

by:westy100697
ID: 2638532
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
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 2639056
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
 
LVL 20

Expert Comment

by:Madshi
ID: 2639182
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
 
LVL 1

Expert Comment

by:nrico
ID: 2639831
>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
 

Author Comment

by:xtvca
ID: 2644141
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
 

Expert Comment

by:westy100697
ID: 2646782
xtcva,
      Did you get it to work ??

WESTY
0
 

Author Comment

by:xtvca
ID: 2648634
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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now