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
Solved

Copying files from Delphi 2.0?

Posted on 1997-06-02
7
156 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
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.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 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