Solved

VB Script create folder and copy data

Posted on 2013-12-14
2
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Configuring Remote Assistance for use with SCCM
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

710 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