Solved

VB Script create folder and copy data

Posted on 2013-12-14
2
212 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult 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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

18 Experts available now in Live!

Get 1:1 Help Now