Solved

copyfiles(long file name) ?

Posted on 2000-03-20
20
293 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
[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
  • 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
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!

 

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
 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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