Solved

Copy Folder

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

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

Thanks
0
Comment
Question by:mwaseem75
  • 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
 
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
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.

 
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

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

Suggested Solutions

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

910 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

19 Experts available now in Live!

Get 1:1 Help Now