Solved

Copy Folder

Posted on 2003-10-30
12
2,189 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

707 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

16 Experts available now in Live!

Get 1:1 Help Now