Solved

Copy files from a LAN computer

Posted on 2004-04-19
7
385 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
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!

 
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

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.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

707 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