Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: VB6 to copy folders and files please

1,229 views
Skip to first unread message

Randy Birch

unread,
Aug 29, 2004, 7:39:29 PM8/29/04
to
You can use SHFileOperation ...
http://vbnet.mvps.org/code/shell/shdirectorycopy.htm

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.


"Beny" <Be...@discussions.microsoft.com> wrote in message
news:E7B3AC08-5B7F-43A7...@microsoft.com...
: Hi everybody,
:
: I need a VB6 program to copy a whole directory ( sub-folders and all
: the files in) to another directory. I developped it using classes and
: collections ( for folders and files in ) but it's too long.
:
: Is there a better way please?. Sorry but I am not a VB6 guru. At least
could
: anyone put me on the proper track please?
:
: Otherwise I would gladly buy such a program.
:
: Thanks a lot
:
: Beny
:
:

Stefan Merwitz

unread,
Aug 30, 2004, 6:44:52 AM8/30/04
to
I created a class that implements some important file operations as well
as the standard windows file open and save dialogs. It does also include
an function called CopyFiles that is based on the api function
SHFileOperations. As this function does display the standard windows
file copy window you do not even have to implement a progress window!

You can find the class on my website: www.VBTricks.de.vu in the section
VB->components->clsFileOperations

Hoe this helps,

Stefan

--
___________________________________www.VBTricks.de.vu
the free resource for Visual Basic, Gambas and Pascal
components, tips & complete projects

www: http://www.VBTricks.de.vu
mail: vbtricks <at> my-mail <dot> ch
_____________________________________________________

Emidio Braga

unread,
Aug 30, 2004, 6:19:27 PM8/30/04
to
hi,

dim fso as object
dim copyfile as string
dim desteny as string
copyfile = "directory\*" or copyfile="file location"
destino = "final directory"
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.copyfile copyfile, desteny, True
Set FSO = Nothing


hope this helps...


Beny

unread,
Aug 30, 2004, 10:59:02 PM8/30/04
to
Hi Emidio,

A note please. You indicated:
FSO.copyfile copyfile, desteny, True

It should be:
FSO.CopyFolder copyfile, desteny, True

Shouldn't be?

Thanks

Beny

Emidio Braga

unread,
Sep 1, 2004, 3:55:09 PM9/1/04
to
yes, you are right... ;)
this code is realy simple, and it works at all. i use it on my own projects.
But remember...

If source contains wildcard characters or destination ends with a path
separator (\), it is assumed that destination is an existing folder in which
to copy matching folders and subfolders. Otherwise, destination is assumed
to be the name of a folder to create. In either case, four things can happen
when an individual folder is copied.

a.. If destination does not exist, the source folder and all its contents
gets copied. This is the usual case.
b.. If destination is an existing file, an error occurs.
c.. If destination is a directory, an attempt is made to copy the folder
and all its contents. If a file contained in source already exists in
destination, an error occurs if overwrite is false. Otherwise, it will
attempt to copy the file over the existing file.
d.. If destination is a read-only directory, an error occurs if an attempt
is made to copy an existing read-only file into that directory and overwrite
is false.
An error also occurs if a source using wildcard characters doesn't match any
folders.

The CopyFolder method stops on the first error it encounters. No attempt is
made to roll back any changes made before an error occurs.

You must prevent this situations.... ;)


0 new messages