Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2206
  • Last Modified:

Copy Folder

Hi

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

Thanks
0
mwaseem75
Asked:
mwaseem75
  • 6
  • 4
1 Solution
 
namasi_navaretnamCommented:
FileCopy ( sourcefile, targetfile {, replace } )

integer li_FileNum

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

HTH

Namasi Navaretnam
0
 
namasi_navaretnamCommented:
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
 
namasi_navaretnamCommented:
No. That just copies the files not folder. Ignore my posting above
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Vikas_DixitCommented:
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
 
namasi_navaretnamCommented:
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
 
namasi_navaretnamCommented:
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
 
Vikas_DixitCommented:

What error did you get ??

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

regards,
Vikas Dixit
0
 
Vikas_DixitCommented:
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
 
namasi_navaretnamCommented:
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.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now