Solved

Copying files from Delphi 2.0?

Posted on 1997-06-02
7
155 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
  • 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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 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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

786 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