[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Copy files from a LAN computer

Posted on 2004-04-19
7
Medium Priority
?
395 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
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 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