百度空间 | 百度首页 
 
查看文章
 
一个扩展dir命令的vbs脚本
2008年05月10日 星期六 上午 01:30

'CMD下的dir好像没法列出从某段时间到某段时间的文件,所以写了这个小东东

set Arg=Wscript.Arguments
If Arg.Count=0 then

Wscript.echo chr(9)&chr(9)&space(4)&"Xdir v0.1"
Wscript.echo ""
Wscript.echo chr(9)&"cscript dir.vbs path time1 time2 ext"
Wscript.echo chr(9)&"cscript dir.vbs d:\test 20080101 20080430 doc"
Wscript.Quit
End If
Path=Arg(0)
Time1=Arg(1)
Time2=Arg(2)
Ext=Arg(3)
FileTotal = 0
DirTotal = 0
FileTotalsize=0
TimeSpend = Timer
myFind Path
TimeSpend = round(Timer - TimeSpend,2)
txtResult = "搜索完成!" & vbCrLf & "共找到文件:" & FileTotal & "个." & vbCrLf & "共搜索目录:" & DirTotal & "个." &vbcrlf&"文件总数大小"&FormatNumber(FileTotalsize/1024,0)&"kB"& vbCrLf & "用时:" & TimeSpend & "秒."

wscript.echo txtResult

Sub myFind(ByVal thePath)
  
Dim fso, myFolder, myFile, curFolder
Set fso = wscript.CreateObject("scripting.filesystemobject")
Set curFolders = fso.getfolder(thePath)
DirTotal = DirTotal + 1
If curFolders.Files.Count > 0 Then
For Each myFile In curFolders.Files
If InStr(1, LCase(Fso.GetExtensionName(myFile.Name)), ext) > 0 And Gtime(myFile.DateCreated) >Time1 And Gtime(myFile.DateCreated)<Time2 Then
wscript.echo FormatPath(thePath) & "\" & myFile.Name
FileTotal = FileTotal + 1
FileTotalsize = FileTotalsize + myFile.size
End If
Next
End If
  
If curFolders.subfolders.Count > 0 Then
For Each myFolder In curFolders.subfolders
myFind FormatPath(thePath) & "\" & myFolder.Name  
Next
End If

End Sub

Function FormatPath(ByVal thePath)

thePath = Trim(thePath)
FormatPath = thePath
If Right(thePath, 1) = "\" Then FormatPath = Mid(thePath, 1, Len(thePath) - 1)

End Function


Function Gtime(str)
str=FormatDateTime(str,2)
str1=Split(str,"-",-1,1)
If len(str1(1))=1 then str11="0"&str1(1)
If len(str1(2))=1 then str12="0"&str1(2)
Gtime=str1(0)&str11&str12
End Function


类别:每天一例 | 添加到搜藏 | 浏览() | 评论 (6)
 
最近读者:
 
网友评论:
1
2008年05月10日 星期六 下午 12:45 | 回复
好东东,哈。
 
2
2008年05月10日 星期六 下午 12:49 | 回复
顶了 嘿额!
 
3
2008年05月10日 星期六 下午 02:51 | 回复
好东西
 
4
2008年07月30日 星期三 上午 02:03 | 回复
LogParser "SELECT TOP 10 Path, Name, Size,LastAccessTime FROM C:\downloads\*.* where LastAccessTime>TIMESTAMP('01/01/2004', 'MM/dd/yyyy') and TO_LOWERCASE(name) like '%a%' ORDER BY Size DESC" -i:FS -useLocalTime:OFF -preserveLastAccTime:ON -recurse:-1
 
5
2009年02月27日 星期五 下午 10:55 | 回复
看不懂
 
6
2009年09月14日 星期一 下午 03:16 | 回复
qq
 
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu