Solved

Copying files from Network drive to network drive using UNC paths

Posted on 2003-11-19
5
323 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Communication Between RC4 Delphi <-> PHP 3 113
Using idhttp to login to instagram 2 89
FMX and jaudiotracker playing memory stream 29 77
Dynamically Created Query 3 55
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

774 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