Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() "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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Save file in a new folder, but create folder only if folder doesn't already exist? | Excel Programming | |||
Check if folder exists, if yes just copy sheet in to folder? | Excel Programming | |||
Copy folder and paste to another folder | Excel Programming | |||
How to copy 30 csv files from a folder to another folder | Excel Programming | |||
Create Folder / Copy Folder / Replace | Excel Programming |