您好,登錄后才能下訂單哦!
這篇文章主要介紹了如何使用vbs實現一個擴展時間段的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
感謝你能夠認真閱讀完這篇文章,希望小編分享的“如何使用vbs實現一個擴展時間段的dir命令”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。