无法使用FileSystemObject通过DateLastModified进行筛选 [英] Unable to filter by DateLastModified with FileSystemObject
问题描述
您好
任何人都能够确定我的IF声明为什么会产生乱码? 我尝试过英国约会,美国约会。 它给出了不同的结果,但仍然是垃圾!
Anyone able to identify why my IF statement is producing gibberish? I've tried with UK dates, American dates. It gives different results, but still rubbish!
(由于某种原因,插入代码块不起作用,所以我不得不即兴发挥 - 抱歉!)
(For some reason, insert code block isn't working, so I had to improvise - sorry!)
谢谢
Martin
========== =====================================
===============================================
===============================================
===============================================
推荐答案
这里有一些问题。首先,您需要在GetFolder中向C:添加尾随\,否则您将从运行脚本的位置获得结果。其次,您需要在测试日期周围使用CDate()以允许测试工作。这是你的
代码,略微调整:
You've got a few issues here. First off, You'll need to add a trailing \ to C: in GetFolder or you'll get results from where the script is run from. Secondly, you'll need to use CDate() around your testing date to allow for the test to work. Here's your code, slightly tweaked:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fso, ts, fileObj, TextLine, FileName
Dim objFolder, objFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFolder = fso.GetFolder("C:\")
FileName = "c:\test.txt"
fso.CreateTextFile FileName
Set fileObj = fso.GetFile(FileName)
Set ts = fileObj.OpenAsTextStream(ForWriting, TristateUseDefault)
For Each objFile In objFolder.Files
If objFile.DateLastModified > CDate("01/01/2013") THEN
ts.WriteLine objFile.DateLastModified & " AFTER" & " " & objFile.Name
ELSE
ts.WriteLine objFile.DateLastModified & " BEFORE" & " " & objFile.Name
End If
Next 'objFile
ts.Close
CDate语法:
http://www.devguru .com / technologies / vbscript / 13904
这篇关于无法使用FileSystemObject通过DateLastModified进行筛选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!