Solved

Copy Folder

Posted on 2003-10-30
12
2,193 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
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…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

773 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