Solved

Copy Folder

Posted on 2003-10-30
12
2,197 Views
Last Modified: 2013-12-26
Hi

How can I copy whole folder from one drive to another?

Thanks
0
Comment
Question by:mwaseem75
[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
  • 6
  • 4
12 Comments
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 9649571
FileCopy ( sourcefile, targetfile {, replace } )

integer li_FileNum

li_FileNum = FileCopy ("jazz.gif" , "C:\emusic\jazz.gif", FALSE)

HTH

Namasi Navaretnam
0
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 9649595
PFC Example:

f_SetFileSrv(inv_filesrv, TRUE)

Integer   li_return

li_return = inv_filesrv.of_FileCopy("c:\namasi", &
                     "d:\namesi", TRUE)

CHOOSE CASE li_return
            CASE -1
         MessageBox("Copy Error", &
            "Error opening source file")
            CASE -2
         MessageBox("Copy Error", &
            "Error reading source file")
            CASE -3
         MessageBox("Copy Error", &
            "Error accessing target file")

END CHOOSE

HTH
0
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 9649634
No. That just copies the files not folder. Ignore my posting above
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:Vikas_Dixit
ID: 9651502
0
 
LVL 8

Accepted Solution

by:
Vikas_Dixit earned 100 total points
ID: 9651571
The declaration :

Function long SHFileOperation( Ref SHFILEOPSTRUCT lpFileOp ) Library "SHELL32.DLL" Alias For "SHFileOperationA"

global type shfileopstruct from structure
      long            hwnd
      unsignedlong            wfunc
      long            pfrom
      string            pto
      unsignedlong            fflags
      boolean            fanyoperationsaborted
      long            hnamemappings
      string            lpszprogresstitle
end type

The values of related constants/Flags you can find out in the file shellapi.h


Hope this helps
regards,
Vikas Dixit
0
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 9655229
If you are not too familiar with APIs, you can use run command

Example:
Method 1
String ls_cmd
ls_cmd = "xcopy c:\source c:\destination /s /Y /I"
RUN(ls_cmd, Minimized!)

Method 2

A) Declare this API

FUNCTION long ShellExecuteA(long hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, long nShowCmd) LIBRARY "SHELL32.DLL"

B)

String ls_cmdfile
ls_cmdfile= "c:\mycmd.bat"

// First delete done file.
If FileExists(ls_cmdfile) Then
   FileDelete(ls_cmdfile)
End If

ls_command = "xcopy " + ls_src + "  " + ls_dest + "  /s /Y /I"


Ll_FileNum = FileOpen ( ls_cmdfile, LineMode!, Write!, LockWrite!, Replace!)
FileWrite(ll_FileNum, Ls_Command)
FileClose(ll_FileNum)

Ll_Return = ShellExecuteA(0,'open',ls_cmdfile,'','',0)

HTH

Namasi Navaretnam



0
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 9663461
Vikas's approch is the best as RUN command runs independently and PB will not wait for the copy operation to complete.

Vikas, I was trying your approach and getting an error message. Do you have a complete example?

Namasi.
0
 
LVL 8

Expert Comment

by:Vikas_Dixit
ID: 9663640

What error did you get ??

I don't have code.. I will try and let you know..

regards,
Vikas Dixit
0
 
LVL 8

Expert Comment

by:Vikas_Dixit
ID: 9663784
Here's a code that works fine ( Win XP/PB8)..

int FO_DELETE = 3 //&H3
int FOF_ALLOWUNDO = 64 //&H40
int FOF_FILESONLY = 128 //&H80
int FO_COPY = 2 //&H2
ulong FOF_SILENT= 4

Blob{1} lblb_Null
shfileopstruct lst_shfileopstruct
BlobEdit(lblb_Null,1,0)

lst_shfileopstruct.hwnd = Handle(parent)
lst_shfileopstruct.wfunc = FO_COPY
lst_shfileopstruct.pFrom   = blob('C:\temp') + lblb_Null + lblb_Null
lst_shfileopstruct.pto   = blob('E:\temp') + lblb_Null + lblb_Null
Setnull(lst_shfileopstruct.lpszprogresstitle)
//lst_shfileopstruct.fflags = FOF_SILENT

shfileoperation( lst_shfileopstruct)

Only change needed was to decalre the pFrom    and pTo as blobs in the structure. There may be other ways...

regards,
Vikas D
0
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 9663993
Works!! I was getting an 'error calling external function' earlier!!

Great!!!

Namasi.
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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Suggested Courses

710 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