Solved

Copying files from Network drive to network drive using UNC paths

Posted on 2003-11-19
5
321 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
ID: 9780514

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
ID: 9780606

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
ID: 9785318
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

17 Experts available now in Live!

Get 1:1 Help Now