Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.excel.programming > #108343 > unrolled thread

Copy a folder's contents into another folder?

Started by"Robert Crandal" <noreply2me@yahoo.com>
First post2015-12-16 19:40 -0700
Last post2015-12-17 20:17 +0100
Articles 10 — 3 participants

Back to article view | Back to microsoft.public.excel.programming


Contents

  Copy a folder's contents into another folder? "Robert Crandal" <noreply2me@yahoo.com> - 2015-12-16 19:40 -0700
    Re: Copy a folder's contents into another folder? GS <gs@v.invalid> - 2015-12-17 01:01 -0500
      Re: Copy a folder's contents into another folder? GS <gs@v.invalid> - 2015-12-17 13:35 -0500
    Re: Copy a folder's contents into another folder? Claus Busch <claus_busch@t-online.de> - 2015-12-17 10:32 +0100
      Re: Copy a folder's contents into another folder? "Robert Crandal" <noreply2me@yahoo.com> - 2015-12-17 12:53 -0700
        Re: Copy a folder's contents into another folder? GS <gs@v.invalid> - 2015-12-17 15:52 -0500
          Re: Copy a folder's contents into another folder?  (.chm file error) "Robert Crandal" <noreply2me@yahoo.com> - 2015-12-17 16:17 -0700
            Re: Copy a folder's contents into another folder?  (.chm file error) GS <gs@v.invalid> - 2015-12-17 18:36 -0500
              Re: Copy a folder's contents into another folder?  (.chm file error) "Robert Crandal" <noreply2me@yahoo.com> - 2015-12-17 16:56 -0700
    Re: Copy a folder's contents into another folder? Claus Busch <claus_busch@t-online.de> - 2015-12-17 20:17 +0100

#108343 — Copy a folder's contents into another folder?

From"Robert Crandal" <noreply2me@yahoo.com>
Date2015-12-16 19:40 -0700
SubjectCopy a folder's contents into another folder?
Message-ID<uaqdnarMVc4uve_LnZ2dnUVZ5hKdnZ2d@giganews.com>
Consider the following code:

FSO.CopyFolder "C:\MyData" "C:\Backup"

This will create a NEW folder named "Backup" which has the identical
contents of "MyData".

For my purposes, suppose the "C:\Backup" folder already exists, and
my goal is to copy the "MyData" folder INTO the "Backup" folder.
Is this possible with the "CopyFolder" function?

Also, does Excel provide other functions or means for copying
and pasting folders?

Thanks!


[toc] | [next] | [standalone]


#108344

FromGS <gs@v.invalid>
Date2015-12-17 01:01 -0500
Message-ID<n4tiv2$s8l$1@dont-email.me>
In reply to#108343
> Consider the following code:
>
> FSO.CopyFolder "C:\MyData" "C:\Backup"
>
> This will create a NEW folder named "Backup" which has the identical
> contents of "MyData".
>
> For my purposes, suppose the "C:\Backup" folder already exists, and
> my goal is to copy the "MyData" folder INTO the "Backup" folder.
> Is this possible with the "CopyFolder" function?
>
> Also, does Excel provide other functions or means for copying
> and pasting folders?
>
> Thanks!

The scripting CHM states...

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

There's an optional 3rd arg to this FSO method...

  Object.CopyFolder (source, destination[, overwrite])

..where you can replace or preserve existing contents in the 
destination location.

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#108346

FromGS <gs@v.invalid>
Date2015-12-17 13:35 -0500
Message-ID<n4uv47$v9c$1@dont-email.me>
In reply to#108344
Here's the remarks from Script56.chm (which is free) for the 
CopyFolder() method of FSO...

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

[JScript]
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CopyFolder ("c:\\mydocuments\\letters\\*", "c:\\tempfolder\\")
[VBScript]
FileSystemObject.CopyFolder "c:\mydocuments\letters\*", 
"c:\tempfolder\"
But you cannot use:

[JScript]
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CopyFolder ("c:\\mydocuments\\*\\*", "c:\\tempfolder\\")
[VBScript]
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.

If destination does not exist, the source folder and all its contents 
gets copied. This is the usual case.
If destination is an existing file, an error occurs.
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.
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.

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#108345

FromClaus Busch <claus_busch@t-online.de>
Date2015-12-17 10:32 +0100
Message-ID<n4tvbm$10f$1@dont-email.me>
In reply to#108343
Hi Robert,

Am Wed, 16 Dec 2015 19:40:51 -0700 schrieb Robert Crandal:

> Consider the following code:
> 
> FSO.CopyFolder "C:\MyData" "C:\Backup"

you can also copy the files of this folder to another folder, e.g.:

Sub CopyFile()
Dim objFSO As Object, objFolder As Object, objFile As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.getfolder("C:\MyData")

For Each objFile In objFolder.Files
    objFile.Copy  "C:\Backup\"
Next

End Sub


Regards
Claus B.
-- 
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional

[toc] | [prev] | [next] | [standalone]


#108348

From"Robert Crandal" <noreply2me@yahoo.com>
Date2015-12-17 12:53 -0700
Message-ID<-NCdnZG_TfJTj-7LnZ2dnUVZ5jGdnZ2d@giganews.com>
In reply to#108345
"Claus Busch" <claus_busch@t-online.de> wrote:
>
>> Consider the following code:
>>
>> FSO.CopyFolder "C:\MyData" "C:\Backup"
>
> you can also copy the files of this folder to another folder, e.g.:
>
> Sub CopyFile()
> Dim objFSO As Object, objFolder As Object, objFile As Object
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFolder = objFSO.getfolder("C:\MyData")
>
> For Each objFile In objFolder.Files
>    objFile.Copy  "C:\Backup\"
> Next
>
> End Sub

Last night, I discovered this solution:

     FSO.CopyFolder "C:\MyData" "C:\Backup\MyData"

This will copy MyData into the Backup directory as a
subdirectory.  In other words, it seems to be equivalent to
copying and pasting one folder INTO another folder.

I still need to test it a little more and possibly experiment with
the "overwrite" parameter that Gary mentioned earlier.



[toc] | [prev] | [next] | [standalone]


#108349

FromGS <gs@v.invalid>
Date2015-12-17 15:52 -0500
Message-ID<n4v763$1k2$1@dont-email.me>
In reply to#108348
Robert,
It would serve you well to have a copy of Script56.chm if you use any 
of the Windows Scripting Technologies...

  http://www.microsoft.com/en-us/download/details.aspx?id=2764

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#108350 — Re: Copy a folder's contents into another folder? (.chm file error)

From"Robert Crandal" <noreply2me@yahoo.com>
Date2015-12-17 16:17 -0700
SubjectRe: Copy a folder's contents into another folder? (.chm file error)
Message-ID<g96dndXyupc_3-7LnZ2dnUVZ5tqdnZ2d@giganews.com>
In reply to#108349
"GS" <gs@v.invalid> wrote:
>
> It would serve you well to have a copy of Script56.chm if you use any of 
> the Windows Scripting Technologies...
>
>  http://www.microsoft.com/en-us/download/details.aspx?id=2764
>

I saved the .chm file on my desktop, but nothing appears viewable to
me.  If I click on any article I get the following error message:

  Navigation to webpage was canceled

     What you can try:
      * Retype the address

Am I missing a component on my system???


[toc] | [prev] | [next] | [standalone]


#108351 — Re: Copy a folder's contents into another folder? (.chm file error)

FromGS <gs@v.invalid>
Date2015-12-17 18:36 -0500
SubjectRe: Copy a folder's contents into another folder? (.chm file error)
Message-ID<n4vgoq$p09$1@dont-email.me>
In reply to#108350
> "GS" <gs@v.invalid> wrote:
>>
>> It would serve you well to have a copy of Script56.chm if you use 
>> any of the Windows Scripting Technologies...
>>
>>  http://www.microsoft.com/en-us/download/details.aspx?id=2764
>>
>
> I saved the .chm file on my desktop, but nothing appears viewable to
> me.  If I click on any article I get the following error message:
>
>   Navigation to webpage was canceled
>
>      What you can try:
>       * Retype the address
>
> Am I missing a component on my system???

No, you're not missing anything on your system. The file is HTML based 
and so Windows has *Blocked* its content during the download process 
for security. You need to *Unblock* it from its 'Properties' dialog!

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#108352 — Re: Copy a folder's contents into another folder? (.chm file error)

From"Robert Crandal" <noreply2me@yahoo.com>
Date2015-12-17 16:56 -0700
SubjectRe: Copy a folder's contents into another folder? (.chm file error)
Message-ID<7L6dndMkJrwn1u7LnZ2dnUVZ5vednZ2d@giganews.com>
In reply to#108351
"GS" <gs@v.invalid> wrote:
>
> No, you're not missing anything on your system. The file is HTML based and 
> so Windows has *Blocked* its content during the download process for 
> security. You need to *Unblock* it from its 'Properties' dialog!
>

Aha, there it is.  Thanks, this file will be very useful to me.


[toc] | [prev] | [next] | [standalone]


#108347

FromClaus Busch <claus_busch@t-online.de>
Date2015-12-17 20:17 +0100
Message-ID<n4v1jt$aee$1@dont-email.me>
In reply to#108343
Hi Robert,

Am Wed, 16 Dec 2015 19:40:51 -0700 schrieb Robert Crandal:

> Also, does Excel provide other functions or means for copying
> and pasting folders?

if you want to move the folder instead of copying you could use the Name
method:
Name OldPath As NewPath


Regards
Claus B.
-- 
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional

[toc] | [prev] | [standalone]


Back to top | Article view | microsoft.public.excel.programming


csiph-web