Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I copy a folder from one server to another using delphi? 2

Status
Not open for further replies.

ndolson

Programmer
May 3, 2001
9
US
I am trying to create a simple application that will copy a folder containing multiple crystal reports from a server at one location to multiple servers. I know the way to do this logically but I am new to Delphi and I was looking for some help with the actual coding for this. Is there an easy way to do this?
 
look for fileopen/filewrite in the helpfiles (type 'fileopen' or 'filewrite', put the cursor inside it and press ctrl-F1), it even has some examples.

HTH, TonHu
 
How about old and good CopyFile function? It needs 3 parameters: source filefame, dest filename and FailIfExists flag.

--- markus
 
How do I pass the file name to the CopyFile function? My file name is c:\test\foldertocopy\.
 
I've found this in my D3 api book, but I may be overengineering here and there may be a newer way to do this.


procedure TForm1.Button1Click(Sender: TObject);
var
FileOpInfo: TSHFileOpStruct; // holds information about the file
begin
with FileOpInfo do
begin
Wnd := Form1.Handle;
wFunc := FO_COPY; // perform a copy
pFrom := PChar('c:\test\foldertocopy'+#0+#0); // the source
pTo := PChar(ToDirectory); // the destination directory
fFlags := FOF_WANTMAPPINGHANDLE;
end;

{perform the file operation}
SHFileOperation(FileOpInfo);

{the fFlags member contains FOF_WANTMAPPINGHANDLE, indicating
that a handle to an array of TSHNameMapping structures was
returned in the FileOpInfo.hNameMappings member. this must
be freed using the SHFreeNameMappings function.}
SHFreeNameMappings(GlobalHandle(FileOpInfo.hNameMappings));
end;

NOTE, in the original example pFrom was assigned a filename rather than a directory. Try it with a dir first, if unsuccessful, you may have to loop thru each file in the source directory, but that sounds cumbersome and sure it can't be right.

good luck
lou

p.s. HAve you tried searching the Borland.com website a general search on the net.
 
hi

In additional, here are some of the other options, which are pretty useful:-

wFunc:-
FO_DELETE
FO_MOVE
FO_RENAME

fFlags:-
FOF_ALLOWUNDO - delete to recycle bin
FOF_FILESONLY - perform on files with wildcard, eg *.pas
FOF_MULTIDESTFILES - pTo has one dest. file for each source file instead of one dir. to which all soure files are deposited.
FOF_NOCONFIRMATION - no prompt dlg. Same as 'Yes to All'
FOF_NOCONFIRMMKDIR - creates new dir if needed
FOF_NOERRORUI - no visual indication, if errors.
FOF_RENAMEONCOLLISION - file given new name if file exists already (eg Copy #1 of ...)
FOF_SILENT - does not display progress dlg
FOF_SIMPLEPROGRESS - shows progress dlg but not filenames
FOF_WANTMAPPINGHANDLE - the hNameMappings member receives a handle toa filename mapping object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top