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.CreateObjec t("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\vbsLo gg.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
Set oShell=WScript.CreateObjec
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\vbsLo
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
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\2 015 12:37:39 PM\
The filename, directory name, or volume label syntax is incorrect.
It has not created any folder with currentdate.Please help
2015/07/13 12:37:39 ERROR 123 (0x0000007B) Accessing Destination Directory D:\WebSites\Archive\7\13\2
The filename, directory name, or volume label syntax is incorrect.
It has not created any folder with currentdate.Please help
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
to:Open in new window
see if this met your requirement?