Solved

Copying files from Delphi 2.0?

Posted on 1997-06-02
7
158 Views
Last Modified: 2010-04-06
How do I copy files using a delphi-application?(and a wildcard). I have tried to do it this way:

Procedure Button1Click....
Var CMode:boolean;
Begin
   CMode:=False;
   CopyFile('C:\test\*.txt','A:',CMode);
End;  

Looks good doesn't it??The only problem is that it doesn't work. Why??
(I am using Delphi Developer 2.0)
Thanks!!
Erik N
0
Comment
Question by:Erik N
[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
  • 4
  • 3
7 Comments
 
LVL 4

Accepted Solution

by:
erajoj earned 50 total points
ID: 1336739
Try something like this instead:

procedure Button1Click....
var
  CMode    : Boolean;
  SRec     : TSearchRecord;
  Path, Dir: string;
begin
  CMode := False;
  Path  := 'C:\test\*.txt';
  Dir   := EctractFileDir(Path);
  if FindFirst(Path, faAnyFile, SRec)=0 then repeat
    with SRec do CopyFile(Dir + Name, 'A:' + Name, CMode);
  until FindNext(SRec)<>0;
  FindClose(SRec);
end;

/// John

0
 

Author Comment

by:Erik N
ID: 1336740
Sorry erajoj, it didn't work.
Error occured: 'No compability between 'String' and 'Pchar'!
What should I do???
Erik N
0
 

Author Comment

by:Erik N
ID: 1336741
Sorry erajoj, it didn't work.
Error occured: 'No compability between 'String' and 'Pchar'!
What should I do???
Erik N
0
Industry Leaders: 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!

 
LVL 4

Expert Comment

by:erajoj
ID: 1336742
Sorry!
I saw it when I sent it, but I thought you knew what to do.
Just typecast the strings as PChars like this:
CopyFile(PChar(Dir + Name), PChar('A:' + Name), CMode);
This should work. If it doesn't; let me know!

/// John

0
 

Author Comment

by:Erik N
ID: 1336743
Sorry erajoj, it didn't work this time either!
My floppydrive is completely dead!
It seems that the 'Name'-var. gets the name of the form, so I tried to use the ExtractFileNamefunction, but that to didn't work!
This beats me...
Erik N

0
 
LVL 4

Expert Comment

by:erajoj
ID: 1336744
Hi again!

The code below is exactly the code I have tested on my system.
It works!:

procedure TMainForm.Button14Click(Sender: TObject);
var
  CMode    : Boolean;
  SRec     : TSearchRec;
  Path, Dir: string;
begin
  CMode := False;
  Path := 'C:\*.txt';
  Dir := ExtractFileDir(Path);
  if FindFirst(Path, faAnyFile, SRec)=0 then repeat
    with SRec do CopyFile(PChar(Dir + Name), PChar('A:' + Name), CMode);
  until FindNext(SRec)<>0;
  SysUtils.FindClose(SRec);
end;

In the future, if you want more specific help, you need to
increase your grade. Otherwise you will just get pointers.

/// John

0
 

Author Comment

by:Erik N
ID: 1336745
Thank you very much for your time, erajoj.
I'll think about the grade-part in the future...
Over and out!
Erik N

0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

734 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