copy folders to another folder

L

larry

i need a short method of copying the contents of folder
one to folder two. folder one contains 30 folders with
each containing 10 files.

example copy c:\folder one\*.* to c:\folder two\*.*

i need this in vb

thanks
 
M

Martin Seelhofer

Hi there
example copy c:\folder one\*.* to c:\folder two\*.*

You can e.g. achieve this with an API function:

Public Declare Function SHFileOperation Lib "shell32.dll" Alias _
"SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

' use one of these as modifiers
Public Const FOF_SILENT = &H4 ' don't create progress/report
Public Const FOF_SIMPLEPROGRESS = &H100 ' means don't show names of files
Public Const FOF_NOCONFIRMMKDIR = &H200 ' don't confirm making any needed
dirs

' use one of these as the operation
Public Const FO_COPY = &H2
Public Const FO_DELETE = &H3
Public Const FO_MOVE = &H1
Public Const FO_RENAME = &H4


Public Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS
End Type


Sub CopyFiles(src As String, dst As String)
Dim op As SHFILEOPSTRUCT

op.pFrom = src
op.pTo = dst
op.fFlags = FOF_SILENT
op.wFunc = FO_COPY

Call SHFileOperation(op)
End Sub


Usage: CopyFiles "c:\folder one", "c:\folder two"


Cheers,

Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top