Solved

VB Script create folder and copy data

Posted on 2013-12-14
2
214 Views
Last Modified: 2013-12-15
Hi
I need to check via vb script that if folder exist do nothing if folder dose not exist create a folder and then copy all data from 9.4 folder to 9.4_AA
I am getting error on copyfolder
please suggest.



Set fso = CreateObject ("scripting.filesystemobject")
If Not fso.FolderExists( "D:\TAF\9.4_AA") Then
Set objFolder = fso.CreateFolder( "D:\TAF\9.4.2_AA")
End If
Set fso = CreateObject ("scripting.filesystemobject")
Set fso.copyfolder("D:\TAF\9.4","D:\HSCTAF\9.4_AA\")
0
Comment
Question by:theology
2 Comments
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39719245
Hi,
why did you create FSO two times?

Shouldnt it be more like
Set fso = CreateObject("scripting.filesystemobject")
If fso.FolderExists("D:\TAF\9.4_AA") = False Then
	Set objFolder = fso.CreateFolder("D:\TAF\9.4.2_AA")
	fso.copyfolder "D:\TAF\9.4","D:\HSCTAF\9.4_AA\" 
End If

Open in new window

And are you sure that the destination folder is
D:\HSCTAF\9.4_AA\
?

HTH
Rainer
0
 
LVL 6

Accepted Solution

by:
limweizhong earned 500 total points
ID: 39719507
I think you need to just do this:
Dim fso
Set fso = CreateObject("scripting.filesystemobject")
On Error Resume Next
fso.GetFolder("c:\users\home\documents\temp\doc1").Copy "c:\users\home\documents\temp\doc2", False
On Error GoTo 0

Open in new window

because fso.copyfolder seems to be unable to rename the folders it copies.

Edit: I changed the code to fulfil the correct requirements now. This method will automatically create the folder if it does not exist, and will not override an existing folder, even if the contents are different.
0

Featured Post

Make managing Office 365 email signatures a breeze

Are you using Office 365? Having trouble trying to set up email signatures for your users? Getting stressed out managing multiple signatures? Need an easier way to manage? We have a solution for you, try the most-user friendly and powerful signature management tool on the market.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Doubt. 2 57
Randomize in Owl Carousel v1.3.2 6 20
how can i remove string values 2 14
How can i get the length? 7 14
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now