|
今天写了一个vbs的小程序,在qtp里调试的,就发到这里吧,呵呵。
这个程序的目的是:
测试工作基本上都是天天有新build,有时候我们需要关注我们产品所在安装目录的文件(夹)变化,我的程序已经去处了日期的因素,只对文件的大小和名称进行关注。
把我的代码保存成yourname.vbs,然后自己创建一个old.txt的文件就行了,执行以后就产生了new.txt result.txt文件,把new修改成old.txt就可以第2天接着用了。有不明白的问我啊,谁有好的建议也可以说。大家都自己修改一下使用吧,尤其是那句转换目录和生成文件的地方,你们要先修改了才能用。
Set WShell =CreateObject("Wscript.Shell")
curr_d=WShell.currentdirectory
set fso_curr = createobject("Scripting.FileSystemObject")
set conn_folder = fso_curr.getfolder(curr_d)
if conn_folder.isrootfolder then
curr_d=curr_d
else
curr_d=curr_d&"\"
end if
status = WShell.Run("cmd /c c:&cd c:\pro* & cd outlook & dir /s >c:\tmp.txt",1,True) '自己修改一下这句话吧。按照你的要求
Set wshell=nothing
Dim tmp_file : tmp_file = "c:\tmp.txt"
Dim old_file : old_file = curr_d&"old.txt"
Dim new_file : new_file = curr_d&"new.txt"
Dim result : result = curr_d&"result.txt"
msgbox "Welcome to use liang's program to compare your files in a specific folder, you can change the destination folder anyway.thanks , email:jacky_25@tom.com
Remove_date tmp_file,new_file
Compare old_file,new_file,result
finish tmp_file
Private Function Remove_date(tmp_file,new_file)
Dim fso_date : Set fso_date = CreateObject("Scripting.FileSystemObject")
Dim tmp_str : Set tmp_str = fso_date.OpenTextFile(tmp_file)
Dim new_str : Set new_str = fso_date.CreateTextFile(new_file)
Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = "\d+\/\d+\/\d+ \d+\:\d+ [AP][M]" ' Set pattern. [0-9][0-9]:[0-9][0-9] [AP][M]
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
While not tmp_str.atendofstream
Dim line : line=tmp_str.readline
Dim r_result : r_result = regEx.replace(line,"")
new_str.writeline r_result
wend
tmp_str.close
new_str.close
set fso_date=nothing
End Function
Private Function Compare(old_file,new_file,result)
Set fso_compare=CreateObject("Scripting.FileSystemObject")
Set Str_old = fso_compare.Opentextfile(old_file)
Set Str_new = fso_compare.Opentextfile(new_file)
Set Str_result = fso_compare.createtextfile(result)
While Not Str_old.atendofstream
String_old=Str_old.readline
String_new=Str_new.readline
If String_old <> String_new Then
Str_result.writeline "str_old:"&string_old
Str_result.writeline "str_new:"&string_new
Str_result.writeline "*******************************************************"
End If
Wend
Str_old.close
Str_new.close
Str_result.close
set fso_compare=nothing
End Function
private function finish(dir)
set dir_obj = createobject("Scripting.FileSystemObject")
set file_obj = dir_obj.getFile(dir)
file_obj.delete
set dir_obj=nothing
set file_obj=nothing
end function
[ 本帖最后由 jackymail 于 2007-7-17 17:02 编辑 ] |
|