Solved

Copy files from a LAN computer

Posted on 2004-04-19
7
383 Views
Last Modified: 2010-04-05
Hi Experts...

I need to write a program that periodically reads and copy a folder from a LAN computer in DELPHI... i would like to know if there's a way to do this or if there's a component i can download to do this write and read process.

Thanx,

rbraym
0
Comment
Question by:rbraym
[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
7 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10866280

   use the file full path, for example :

    \\computername\sharedfolder\filesname.ext

   Of course the directory have to be shared. Then use the standart functions for files. If you want to access it via HTTP or FTP - reffer to Indy components.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10866579
uses
  ............., IdGlobal;

procedure TForm1.Button_Lan_CopyClick(Sender: TObject);
var
  S:      string;
  T:      string;
  R:      string;
begin
  S := '\\Emo\C:\Q_20932619.txt';
  R := 'F:\Q_20932619.txt';
  case CopyFileTo(S, R) of
    True:  T := 'was SUCCESSFULY COPIED to ';
    False: T := 'was NOT SUCCESSFULY COPIED to ';
  end;
  Memo1.Lines.Add(S);
  Memo1.Lines.Add(T);
  Memo1.Lines.Add(R);
  Memo1.Lines.Add('--------------------------------------');
end;
0
 
LVL 12

Accepted Solution

by:
esoftbg earned 50 total points
ID: 10867466
Copy a Folder. I can not test under LAN, only tested between HDD's:

function  Copy_Dir(Dir, Source, Target: string): Boolean;
var
  B:      Boolean;
  T:      TSHFileOpStruct;
begin
  B := False;
  if not DirectoryExists(Target+Dir) then
    ForceDirectories(Target);
  try
    Fillchar(T, SizeOf(T), #0);
    with T do
    begin
      Wnd := 0;
      wFunc := FO_COPY;
      pFrom := PChar(Source+Dir + #0#0);
      pTo := PChar(Target+Dir + #0#0);
      fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
    end;
    Application.ProcessMessages;
    B := (SHFileOperation(T)=0);
  finally
    Result := B;
  end;
end;

procedure TForm1.Button_Lan_CopyFolderClick(Sender: TObject);
var
  S:      string;
  T:      string;
  R:      string;
begin
  S := '\\emo\C:';
//  S := 'C:';
  R := 'F:';
  case Copy_Dir('\SFX', S, R) of
    True:  T := 'was SUCCESSFULY COPIED to ';
    False: T := 'was NOT SUCCESSFULY COPIED to ';
  end;
  Memo.Lines.Add(S);
  Memo.Lines.Add(T);
  Memo.Lines.Add(R);
  Memo.Lines.Add('--------------------------------------------------------------------------------------------------------------------------------');
end;
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 11

Expert Comment

by:shaneholmes
ID: 10874215
Look at this previous post:

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20892075.html?query=Copy+Folder&searchType=topic



uses ShellApi;


function CopyDir(const fromDir, toDir: string): Boolean;
var
  fos: TSHFileOpStruct;
begin
  ZeroMemory(@fos, SizeOf(fos));
  with fos do
  begin
    wFunc  := FO_COPY;
    fFlags := 0; //FOF_FILESONLY; // check FOF_* flags for more options
    pFrom  := PChar(fromDir + #0);
    pTo    := PChar(toDir)
  end;
  Result := (0 = ShFileOperation(fos));
end;


note that the pFrom and pTo need to be double null-terminated .. meaning pFrom/pTo must have #0#0 at the end beacause each entry is delimited with a single null terminator

Then pass it a UNC path (fromDir)

 Example:

  \\LanComputerName\Lansharedfolder\


Hope this helps!

Shane
0
 

Author Comment

by:rbraym
ID: 10878456
Thanks...

It helped me a lot!!..

0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10878492
It helped so great, he gave you a B!

I can't understand some peoples train of thought.... <SMILE>

Shane
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10885757
Hi Shane,
I guess rbraym gave me a B because I have some errors in above code:
>  if not DirectoryExists(Target+Dir) then
>    ForceDirectories(Target);
does nothing, it would be:
  if not DirectoryExists(Target+Dir) then
    ForceDirectories(Target+Dir);

and finally it is not needed because
ShFileOperation();
makes target dir if it does not exist

emil
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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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