Vbscript 如何使用此特定脚本创建每日日志文件

Vbscript 如何使用此特定脚本创建每日日志文件,vbscript,Vbscript,我发现这个VBS脚本将Planeplotter(记录飞机的软件)中的数据记录到CSV文件中 现在我的问题是:如何修改这个脚本来创建一个新的CSV文件。现在所有的东西都塞进了一个文件 ' PlanePlotter script for logging active aircraft (including those received by sharing) ' Create a file in the Log Files directory Dim fso, f1, ts Const ForWri

我发现这个VBS脚本将Planeplotter(记录飞机的软件)中的数据记录到CSV文件中

现在我的问题是:如何修改这个脚本来创建一个新的CSV文件。现在所有的东西都塞进了一个文件

' PlanePlotter script for logging active aircraft (including those received by sharing)
' Create a file in the Log Files directory
Dim fso, f1, ts
Const ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateTextFile ("B:\_Mijn Downloads en Werkmap\_Spotten\PlanePlotter\Log\pp_share_log.txt")
Set f1 = fso.GetFile("B:\_Mijn Downloads en Werkmap\_Spotten\PlanePlotter\Log\pp_share_log.txt")
Set ts = f1.OpenAsTextStream(ForWriting, True)

' Tap in to PlanePlotter
Dim MyObject
Set MyObject = GetObject(,"PlanePlotter.Document")

' Write all the aircraft data out to file every minute for 24 hours
while 1
  i = 0
  while i < MyObject.GetPlaneCount()
    hexc = MyObject.GetAllPlaneData(i,0)
    regc = MyObject.GetAllPlaneData(i,1)
    flnc = MyObject.GetAllPlaneData(i,2)
    latf = MyObject.GetAllPlaneData(i,3)
    latc = Cstr(latf)
    latc = Replace(latc,",",".")
    lonf = MyObject.GetAllPlaneData(i,4)
    lonc = CStr(lonf)
    lonc = Replace(lonc,",",".")
    altf = MyObject.GetAllPlaneData(i,5)
    altc = CStr(altf)
    altc = Replace(altc,",",".")
    hedf = MyObject.GetAllPlaneData(i,6)
    hedc = CStr(hedf)
    hedc = Replace(hedc,",",".")
    spdf = MyObject.GetAllPlaneData(i,7)
    spdc = CStr(spdf)
    spdc = Replace(spdc,",",".")
    recc = MyObject.GetAllPlaneData(i,8)
    recc = Replace(recc," ",",") ' put a comma half way through
    icao = MyObject.GetAllPlaneData(i,14)
    shar = MyObject.GetAllPlaneData(i,18)
    verr = MyObject.GetAllPlaneData(i,21)
    verc = CStr(verr)    
    planeinfo = recc + "," + hexc + "," + regc + "," + flnc + "," + icao + "," + altc + "," + latc + "," + lonc + "," + spdc + "," + hedc + "," + shar + "," + verc + ","
    ts.WriteLine (planeinfo)
    i = i + 1
  wend
  ts.WriteLine ("---------")
  Wscript.Sleep 180000 ' 60 Seconds
  n = n - 1
wend
ts.Close
用于记录活动飞机(包括通过共享接收的飞机)的PlanePlotter脚本 '在日志文件目录中创建一个文件 尺寸fso、f1、ts 写入常数=2 设置fso=CreateObject(“Scripting.FileSystemObject”) fso.CreateTextFile(“B:\\u Mijn下载Werkmap\\u Spotten\PlanePlotter\Log\pp\u share\u Log.txt”) 设置f1=fso.GetFile(“B:\\ u Mijn下载到Werkmap\\ u Spotten\PlanePlotter\Log\pp\u share\u Log.txt”) 设置ts=f1.OpenAsTextStream(用于写入,为真) '点击平面绘图仪 暗肌体 设置MyObject=GetObject(,“PlanePlotter.Document”) '在24小时内,每分钟将所有飞机数据写入文件 而1 i=0 而我这是:

fso.CreateTextFile ("B:\_Mijn Downloads en Werkmap\_Spotten\PlanePlotter\Log\pp_share_log.txt")
Set f1 = fso.GetFile("B:\_Mijn Downloads en Werkmap\_Spotten\PlanePlotter\Log\pp_share_log.txt")
Set ts = f1.OpenAsTextStream(ForWriting, True)
可以简化为:

Set ts = fso.OpenTextFile("B:\_Mijn Downloads en Werkmap\_Spotten\PlanePlotter\Log\pp_share_log.txt", ForWriting, True)

如果您想每天创建一个新文件(而不覆盖旧文件),您可能需要以下内容:

Function LPad(s)
  LPad = Right("00" & s, 2)
End Function

Function FormatDate(d)
  FormatDate = Year(d) & "-" & LPad(Month(d)) & "-" & LPad(Day(d))
End Function

outputDir = "B:\_Mijn Downloads en Werkmap\_Spotten\PlanePlotter\Log"
basename  = "pp_share_log"
filename  = basename & "_" & FormatDate(Date)

Set ts = fso.OpenTextFile(fso.BuildPath(outputDir, filename), ForWriting, True)
这:

可以简化为:

Set ts = fso.OpenTextFile("B:\_Mijn Downloads en Werkmap\_Spotten\PlanePlotter\Log\pp_share_log.txt", ForWriting, True)

如果您想每天创建一个新文件(而不覆盖旧文件),您可能需要以下内容:

Function LPad(s)
  LPad = Right("00" & s, 2)
End Function

Function FormatDate(d)
  FormatDate = Year(d) & "-" & LPad(Month(d)) & "-" & LPad(Day(d))
End Function

outputDir = "B:\_Mijn Downloads en Werkmap\_Spotten\PlanePlotter\Log"
basename  = "pp_share_log"
filename  = basename & "_" & FormatDate(Date)

Set ts = fso.OpenTextFile(fso.BuildPath(outputDir, filename), ForWriting, True)