Link to home
Start Free TrialLog in
Avatar of Sudhanshum
Sudhanshum

asked on

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.

Regards,
Sudhanshu
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

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

objdestination = "D:\WebSites\Archive"

Open in new window

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

Open in new window


see if this met your requirement?
Avatar of Sudhanshum
Sudhanshum

ASKER

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
SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
https://technet.microsoft.com/en-us/library/ee198903.aspx

Formatting Date and Time Values
https://technet.microsoft.com/en-us/library/ee198902.aspx
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial