Solved

Copying files from Network drive to network drive using UNC paths

Posted on 2003-11-19
5
319 Views
Last Modified: 2010-04-05
Whats the best way to copy files from a network drive using UNC paths?

I want to give the user feed back in the form of a progress bar or the 'flying file' windows animation?  

I also want to make sure that the copied worked ie. Check for a result code.

Any help please.
0
Comment
Question by:nigecooper
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
alijunior earned 63 total points
Comment Utility

You must use normal names of files, like in Windows Explorer.

procedure FileCopy(const FromFile, ToFile: string);
 var
  FromF, ToF: file;
  NumRead, NumWritten: Word;
  Buf: array[1..2048] of Char;
begin
  AssignFile(FromF, FromFile);
  Reset(FromF, 1);            
  AssignFile(ToF, ToFile);      
  Rewrite(ToF, 1);            
  repeat
    BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
    BlockWrite(ToF, Buf, NumRead, NumWritten);
    //You can increment a gauge here!!
  until (NumRead = 0) or (NumWritten <> NumRead);
  CloseFile(FromF);
  CloseFile(ToF);
  //You can reload both files and re-read comparing the value of buffers to
  //warranty the perfect copy
end;
0
 
LVL 2

Expert Comment

by:alijunior
Comment Utility

Like above, use SOurce and Dest like in Windows Explorer.

To verify the copied files here, you can use TFileStream and compare values.

...

uses ShellAPI;

procedure ShellFileCopy(Source, Dest : String);
var Dados: TSHFileOpStruct;
begin
  FillChar(Dados,SizeOf(Dados), 0);
  with Dados do
  begin
    wFunc := FO_COPY;
    pFrom := PChar(Source);
    pTo := PChar(Dest);
    fFlags:= FOF_ALLOWUNDO;
  end;
  SHFileOperation(Dados);
end;

The good point of this way are:

You can use wildchar.
Windows, with a floppy, detects diskfull and ask for another.
Windows shows a default system prograss bar, like explorer.

0
 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 62 total points
Comment Utility
similar to alijunior,

sample, found in my paq

uses shellapi;

//moving file or dir with simple progress
procedure TForm1.Button1Click(Sender: TObject);
var I : Integer;
    opInfo : _SHFILEOPSTRUCT;
begin
  opInfo.pFrom := PChar('YourSource');
  opInfo.pTo   := PChar('YourDestination');
  opInfo.wFunc := FO_MOVE;
  opInfo.fFlags := FOF_NOCONFIRMATION  or
                   FOF_NOCONFIRMMKDIR or
                   FOF_RENAMEONCOLLISION or
                   FOF_SIMPLEPROGRESS;
  opInfo.hNameMappings := nil;
  opInfo.fAnyOperationsAborted := False;
  opInfo.lpszProgressTitle := 'Moving . . .';
  opInfo.Wnd := self.handle;
  SHFileOperation(opInfo);
end;

//copy file or dir with simple progress
procedure TForm1.Button2Click(Sender: TObject);
var I : Integer;
    opInfo : _SHFILEOPSTRUCT;
begin
  opInfo.pFrom := PChar('YourSource');
  opInfo.pTo   := PChar('YourDestination');
  opInfo.wFunc := FO_COPY;
  opInfo.fFlags := FOF_NOCONFIRMATION  or
                   FOF_NOCONFIRMMKDIR or
                   FOF_RENAMEONCOLLISION or
                   FOF_SIMPLEPROGRESS;
  opInfo.hNameMappings := nil;
  opInfo.fAnyOperationsAborted := False;
  opInfo.lpszProgressTitle := 'Copying . . .';
  opInfo.Wnd := self.handle;
  SHFileOperation(opInfo);
end;

meikl ;-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

6 Experts available now in Live!

Get 1:1 Help Now