Automatically create folder in Destination Drive Through Vb Script

I am using robocopy function to copy my file from source to destination using below command.I have created .vbs script like below,I am using Windows2007
Set oShell=WScript.CreateObject("WScript.Shell")
objSource = "C:\Sudhanshu\WebSite"
objdestination = "D:\WebSites\Archive"
strSource = Chr(34) & objSource & Chr(34)
strTarget = Chr(34) & objdestination & Chr(34)
strParms = " /s /MIR /LOG+:" & Chr(34) & "D:\WebSites\Archive\vbsLogg.log" & Chr(34)
oShell.Run "robocopy " & strSource & " " & strTarget & strParms

It is working fine,I have set this to scheduler also.But What I want is if I can create destination file name automatically with today date and time.This way, I will not need to manually create Destination folder name,So it will first create a folder on Destination Drive say I will just mention that location as D:\WebSites so it will create todaydate folder say 13July2015 with time and copy source file to destination file.Please help me.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongCommented:
a quick solution is to use FormatDateTime function in vbscript, like change:

objdestination = "D:\WebSites\Archive"

Open in new window

objdestination = "D:\WebSites\Archive\" & FormatDateTime(now())

Open in new window

see if this met your requirement?
SudhanshumAuthor Commented:
Hi Thanks for reply.I tried your solution.I changed destination file as you mentioned but i got error while ruuning vbs.
2015/07/13 12:37:39 ERROR 123 (0x0000007B) Accessing Destination Directory D:\WebSites\Archive\7\13\2015 12:37:39 PM\
The filename, directory name, or volume label syntax is incorrect.
   It has not created any folder with currentdate.Please help
Ryan ChongCommented:
oops, too quick for above suggestion as windows folder didn't allowed characters like "/" and ":"

hence you can try to format like this instead.

objdestination = "D:\WebSites\Archive\" & replace(replace(FormatDateTime(now()),"/"," "),":"," ")

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(objdestination) = false Then fso.CreateFolder objdestination

Open in new window

Ryan ChongCommented:
you can also referring to links below to format the date/time to the format you intended:

Retrieving Specific Portions of a Date and Time Value

Formatting Date and Time Values
An alternative is to pass the date as part of the robocopy string and let robocopy create the folder. i.e.
'output format: yyyymmddHHnn
ds=((year(dt)*100 + month(dt))*100 + day(dt))*10000 + hour(dt)*100 + minute(dt)
objdestination = "D:\WebSites\Archive"
strTarget  = Chr(34) & objdestination & "\" & ds & Chr(34) 
strParms = " /s /MIR /LOG+:" & Chr(34) & "D:\WebSites\Archive\vbsLogg.log" & Chr(34)
oShell.Run "robocopy " & strSource & " " & strTarget & strParms

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.