PDA

View Full Version : filesystemobject



philfer
05-18-2010, 12:49 PM
Hello

Every time i use the copyfolder method as :

Set MyFolder = fso.CreateFolder("C:\MyDocs\ReportingDatabase" & "\" & SaveDate)

Ms fso.CopyFolder "C:\MyDocs\Reporting Database\Reports","C:\MyDocs\Reporting Database" & "\" & SaveDate

It copies the contents of the folder rather than the folder itself. The file structure within Reporting Database is that there a subfolder called Reports. I create a new subfolder under Reporting Database and give it the name of the reporting date which i have saved to a variable SaveDate. I want to copy the folder Reports (which has a load of spreadsheets in it) and put it in the new dated subfolder for a new set of reports to be generated. This process will be repeated each month with a new subfolder for a new date.

Any ideas???

Thanks

phil

GTO
05-18-2010, 02:56 PM
Ms fso.CopyFolder "C:\MyDocs\Reporting Database\Reports","C:\MyDocs\Reporting Database" & "\" & SaveDate


I am presuming the 'Ms' is a typo?

I believe you need the trailing seperator in the destination directory.

Sub exa()
Dim FSO As FileSystemObject
Dim fsoFolder As Folder

Set FSO = New FileSystemObject
Set fsoFolder = FSO.CreateFolder("D:\2010\2010-05-16\CreatedFolder")
'Needs trailing seperator
FSO.CopyFolder "D:\2010\2010-05-16\ReWrite_DistributedCode", fsoFolder.Path & "\"
End Sub


Hope that helps,

Mark