Solved

Copying files from Delphi 2.0?

Posted on 1997-06-02
7
154 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JSON on ISAPI REST Server using Delphi 2 229
build html 5 client that connect to indy Tidtcpserver 3 350
Using idhttp to login to instagram 2 76
Downloading email attachments 2 67
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…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 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

17 Experts available now in Live!

Get 1:1 Help Now