Variables 如何获取当前月份的数值并将其放入VBScript/.vbs中的变量中

Variables 如何获取当前月份的数值并将其放入VBScript/.vbs中的变量中,variables,date,vbscript,automation,Variables,Date,Vbscript,Automation,我编写了一个.vbs脚本,用当前日志文件向管理员发送电子邮件 以下是我到目前为止的情况: Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("c:\automatic_deployment\filename.txt", ForReading) fileName = objTextFile.ReadLine Ws

我编写了一个.vbs脚本,用当前日志文件向管理员发送电子邮件 以下是我到目前为止的情况:

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\automatic_deployment\filename.txt",    ForReading)
fileName = objTextFile.ReadLine
Wscript.Echo fileName

Dim ToAddress
Dim FromAddress
Dim MessageSubject
Dim MyTime
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
Dim month
ToAddress = "myaddress@myemail.com"
MessageSubject = "Deployment was successful"
MyTime = Now
MessageBody = "Successful deployment. Log file is attached." 
MessageAttachment = "C:\M\XYZ\201206\"&fileName&"_DEV_Log.txt"
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf & MyTime
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
newMail.Send

objTextFile.Close
如果您看到,有一个称为“MessageAttachment”的变量,日志文件将附加在该变量上。在日志文件的目标部分,有201206,表示年份和月份。该文件夹保存2012年6月的日志。那个月每月递增。如您所见,它是硬编码的。 到目前为止效果还不错。但是,我想更进一步,让它更有活力。 我想创建一个变量,获取当前月份的当前值,并将其放入源目标的该部分,如下所示:

month = aqDateTime.GetMonth(Date)
MessageAttachment = "C:\M\XYZ\2012"&month&"\"&fileName&"_DEV_Log.txt"
这样行吗?任何帮助都将不胜感激。 提前谢谢

你可以

dim thisMonth: thisMonth = cstr(month(date))
if (len(thisMonth) = 1) then thisMonth = "0" & thisMonth
制作

"C:\M\XYZ\2012" & thisMonth & "\" & fileName & "_DEV_Log.txt"
相等的

年度(日期)
本年度)


Alex K.,感谢您的快速回复。第二条线到底在干什么?你能解释一下吗?再次感谢。
"C:\M\XYZ\201206\XXX_DEV_Log.txt"
<%
current_month = DatePart("m",date) 

Response.Write current_month 
%>