SoFunction
Updated on 2025-04-08

A vbs script for dir command that extends the time period

Core code

set Arg= 
If =0 then 

 chr(9)&chr(9)&space(4)&"Xdir v0.1" 
 "" 
 chr(9)&"cscript  path time1 time2 ext" 
 chr(9)&"cscript  d:\test 20080101 20080430 doc" 
 
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 = "Search completed!" & vbCrLf & "File found in total:" & FileTotal & "indivual." & vbCrLf & "Search directory:" & DirTotal & "indivual." &vbcrlf&"Total File Size"&FormatNumber(FileTotalsize/1024,0)&"kB"& vbCrLf & "Time to use:" & TimeSpend & "Second." 

 txtResult 

Sub myFind(ByVal thePath) 
  
Dim fso, myFolder, myFile, curFolder 
Set fso = ("") 
Set curFolders = (thePath) 
DirTotal = DirTotal + 1 
If  > 0 Then 
For Each myFile In  
If InStr(1, LCase(()), ext) > 0 And Gtime() >Time1 And Gtime()<Time2 Then 
 FormatPath(thePath) & "\" &  
FileTotal = FileTotal + 1 
FileTotalsize = FileTotalsize +  
End If 
Next 
End If 
  
If  > 0 Then 
For Each myFolder In  
myFind FormatPath(thePath) & "\" &   
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 

This is all about this article. I hope everyone will support me in the future.