Solved

Copying files from Delphi 2.0?

Posted on 1997-06-02
7
153 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

10 Experts available now in Live!

Get 1:1 Help Now