Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB Script create folder and copy data

Posted on 2013-12-14
2
Medium Priority
?
223 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
The article covers five tools all IT professionals should know about, as they up productivity by a great deal!
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

783 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