Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Copy a folder's contents into another folder?

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!



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Copy a folder's contents into another folder?

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Copy a folder's contents into another folder?

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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Copy a folder's contents into another folder?

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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Copy a folder's contents into another folder?

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


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Copy a folder's contents into another folder?


"Claus Busch" 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.




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Copy a folder's contents into another folder?

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/downl...s.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
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Copy a folder's contents into another folder? (.chm file error)

"GS" 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/downl...s.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???



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Copy a folder's contents into another folder? (.chm file error)

"GS" 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/downl...s.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
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Copy a folder's contents into another folder? (.chm file error)

"GS" 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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save file in a new folder, but create folder only if folder doesn't already exist? nbaj2k[_40_] Excel Programming 6 August 11th 06 08:41 PM
Check if folder exists, if yes just copy sheet in to folder? Simon Lloyd[_787_] Excel Programming 3 June 19th 06 03:44 PM
Copy folder and paste to another folder ddiicc Excel Programming 4 July 21st 05 02:47 PM
How to copy 30 csv files from a folder to another folder ddiicc Excel Programming 1 July 17th 05 09:42 AM
Create Folder / Copy Folder / Replace Murray Outtrim[_2_] Excel Programming 0 February 24th 04 06:40 PM


All times are GMT +1. The time now is 04:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"