?
Solved

Copy files from a LAN computer

Posted on 2004-04-19
7
Medium Priority
?
391 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 150 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Independent Software Vendors: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 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