比较VBScript文件的创建日期 [英] Comparing creation dates of files in VBScript

查看:158
本文介绍了比较VBScript文件的创建日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于某个人来说,这可能是非常明显的,但我在解决VBScript中的错误时遇到了很多麻烦。在脚本中,我在一个目录中运行一堆.zip文件,并处理创建日期在指定范围内的文件。



例如,如果用户输入两个参数9/3/2014和9/5/2014,我只想处理该日期范围内的zip文件。



这是我正在使用的if语句:

 如果Mid(file.NAME,len(file.NAME)-3,4)=.zipAND 
FormatDateTime(file.DateCreated,2)> = Wscript.Arguments(1)AND
FormatDateTime(file.DateCreated,2)< = Wscript.Arguments(2)then

我正在使用FormatDateTime函数从文件创建日期删除时间。这样我应该留下一个很短的日期(mm / dd / yyyy)。



我遇到的问题是我正在处理指定范围之外的日期。例如,如果给定的范围是9/3/2014至9/5/2014,那么我也因为某些原因最终处理9/30/2014。任何人都可以帮助解决这个问题?

解决方案

FormatDateTime()和.Argments项的返回值都是 。 (stringyfied)数字的字符串比较会给出不便之处:

 >> WScript.Echo CStr(5 <30)
>> WScript.Echo CStr(5<30)
>>
True
False

使用 CDate()将.Arguments转换为日期和 DateDiff()将它们与.DateCreated进行比较。 p>

This may be very obvious to someone out there but I'm having a lot of trouble trying to solve a bug in VBScript. Within the script, I am running through a bunch of .zip files in a directory and processing ones whose creation date is within a specified range.

For instance, if the user enters two arguments 9/3/2014 and 9/5/2014, I only want to process zip files within that date range.

Here is the if statement I am using:

 If Mid(file.NAME,len(file.NAME)-3,4) = ".zip" AND 
 FormatDateTime(file.DateCreated, 2) >= Wscript.Arguments(1) AND 
 FormatDateTime(file.DateCreated, 2) <= Wscript.Arguments(2) then

I am using the FormatDateTime function to remove the times from the file creation date. That way I should just be left with a short date (mm/dd/yyyy).

The problem I am having is that I am processing dates outside of the given range. For example if the given range is 9/3/2014 to 9/5/2014 then I also end up processing 9/30/2014 for some reason. Can anyone help solve this?

解决方案

Both the return value of FormatDateTime() and the items of .Argments are Strings. A string comparison of (stringyfied) numbers will give inconvenient results:

>> WScript.Echo CStr(5 < 30)
>> WScript.Echo CStr("5" < "30")
>>
True
False

Use CDate() to convert the .Arguments to Dates and DateDiff() to compare them against the .DateCreated.

这篇关于比较VBScript文件的创建日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆