?
Solved

Copying files from Network drive to network drive using UNC paths

Posted on 2003-11-19
5
Medium Priority
?
347 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
[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
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
alijunior earned 252 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 248 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month12 days, 18 hours left to enroll

777 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