Solved

Copy files from a LAN computer

Posted on 2004-04-19
7
376 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
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

18 Experts available now in Live!

Get 1:1 Help Now