一个扩展时间段的dir命令的vbs脚本
程序员文章站
2022-03-21 11:06:13
核心代码
set arg=wscript.arguments
if arg.count=0 then
wscript.echo chr(9)&chr(...
核心代码
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
这篇文章就介绍到这,希望大家以后多多支持。