Vbs script for Dir commands in an extended period

Source: Internet
Author: User

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 = "search complete! "& Vbcrlf &" found files: "& filetotal. "& vbcrlf &" total search directories: "& dirtotal. "& vbcrlf &" total file size "& formatnumber (filetotalsize/, 0) &" kb "& vbcrlf &": "& timespend &" seconds."

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.