Avatar billede blueeye97 Nybegynder
22. juli 2004 - 20:55 Der er 2 kommentarer og
1 løsning

Kopiere mapper incl. undermapper - igen ;o)

Ja, jeg ved godt at jeg lige har accepteret et svar på subj.

Men nu har jeg sq fået lyst til at gøre det via vb. Så her igen:

Hvordan kopierer jeg en hel mappe incl. dens undermapper ?
Avatar billede jpvj Nybegynder
22. juli 2004 - 21:10 #1
Fra http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20642738.html

*********
Dim fso
  Set fso = CreateObject("Scripting.FileSystemObject")
  fso.CopyFolder "c:\sample\*", "d:\test\sample\"
*********

CopyFolder Method
Recursively copies a folder from one location to another.

object.CopyFolder source, destination[, overwrite]

Arguments
object

Required. Always the name of a FileSystemObject.

source

Required. Character string folder specification, which can include wildcard characters, for one or more folders to be copied.

destination

Required. Character string destination where the folder and subfolders from source are to be copied. Wildcard characters are not allowed.

overwrite

Optional. Boolean value that indicates if existing folders are to be overwritten. If True, files are overwritten; if False, they are not. The default is True.

Remarks
Wildcard characters can only be used in the last path component of the source argument. For example, you can use:

FileSystemObject.CopyFolder "c:\mydocuments\letters\*", "c:\tempfolder\"

But you can't use:

FileSystemObject.CopyFolder "c:\mydocuments\*\*", "c:\tempfolder\"

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.
Avatar billede blueeye97 Nybegynder
22. juli 2004 - 21:15 #2
Må jeg prøve.

Takker :o)
Avatar billede blueeye97 Nybegynder
22. juli 2004 - 21:19 #3
Er testet og det virker :o)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester