Vbscript 如何仅将日期附加到具有txt扩展名的文件?

Vbscript 如何仅将日期附加到具有txt扩展名的文件?,vbscript,Vbscript,几天之后,你们帮我解决了我在以下代码中遇到的bug: Set FSO = CreateObject("Scripting.FileSystemObject") Set fldr = FSO.GetFolder("C:\Ebooks\DRY\") curYr=Year(Now) For Each fil In fldr.Files If LCase( Right( fil.Name, 4 ) ) = ".zip" Then zipFilePath = fil.Pat

几天之后,你们帮我解决了我在以下代码中遇到的bug:

Set FSO = CreateObject("Scripting.FileSystemObject") 
Set fldr = FSO.GetFolder("C:\Ebooks\DRY\") 
curYr=Year(Now)
For Each fil In fldr.Files 
    If LCase( Right( fil.Name, 4 ) ) = ".zip" Then 
        zipFilePath = fil.Path 
        temp = file.Name 
        temp = Left( temp, LEN(temp) - 4 ) ' remove the .zip 
        temp = Split( temp, "_" ) ' split base name away from month-day-year 
        temp = (temp(ubound(temp))) ' get just month-day-year 
        temp = Split( temp, "-" ) ' get month day and year separately 
        mn = CINT(temp(0)) ' get the month number 
        dirName = MonthName(mn,True) & temp(2) ' True means get 3 letter abbrev for month 
        objZip.UnPack zipFilePath, "D:\ACS\Current\" 
        FSO.MoveFile zipFilePath, "D:\ACS\" & curYr & "\" & dirName & "\" & fil.Name       
    End If 
Next 
剧本写得很好。所有解压缩的文件都将移动到名为Current的文件夹中,原始zip文件将移动到AcsUrrentyear文件夹中

解压后的文件有两个不同的扩展名:pdf和txt

从周一到周五,代码工作正常,每天我们都将txt文件的内容提取到数据库中

但是,在周末,由于txt文件具有相同的名称,它们会被覆盖,从而导致数据丢失。不会覆盖pdf文件,因为名称始终是唯一的

我想做的是将currentdate和time仅附加到具有txt扩展名的文件中

 if lcase(FSO.GetExtensionName(fil.Name)) = "txt" then
  fil.Name = "datFinal.txt"
我想我有这样做的代码,但不知道如何将其集成到我上面发布的脚本中

这里是我想整合的部分

strDay = Day(now)
strMonth = Month(now)
strYear = Year(now)

strHour = Hour(now)
strMinute = Minute(now)
strSecond = Second(now)

 datFinal = strYear & "/" & strMonth & "/" & strDay & " " & strHour & ":" & strMinute & ":" & strSecond
'现在,将日期附加到任何具有txt扩展名的文件

 if lcase(FSO.GetExtensionName(fil.Name)) = "txt" then
  fil.Name = "datFinal.txt"
我该怎么办

更好的是,我可以在我发布的代码中添加一行代码,不允许覆盖txt文件吗


非常感谢您的帮助。

或者每天在D:\ACS\Current\下创建一个新的子文件夹,然后解压缩到该文件夹,如

date_folder = strYear & strMonth & strDay
FSO.CreateFolder ("D:\ACS\Current\" & date_folder)
objZip.UnPack zipFilePath, "D:\ACS\Current\" & date_folder


解压到一个临时文件夹,并将其中的文件移动到D:\ACS\Current\中,同时应用您的逻辑,这样它们就不会相互覆盖。

不客气,我建议填充strMonth和strDay的结果,以获得一个很好的可排序子文件夹列表,因此是20120518而不是2012518