vbs 列出该目录下所有文件和文件夹的类型,大小,和所有者
程序员文章站
2022-04-10 07:59:45
getowner.vbs用法,在命令行下:getowner.vbs 目录名会在相应目录下生成一个txt.txt文件,内里列出该目录下所有文件和文件夹的类型,大小,和所有者...
getowner.vbs用法,在命令行下:getowner.vbs 目录名会在相应目录下生成一个txt.txt文件,内里列出该目录下所有文件和文件夹的类型,大小,和所有者
注意:大小以mb为单位,小于1mb的就显示为0mb,
以下是代码:
g = wscript.arguments(0)
set ofso = createobject("scripting.filesystemobject")
set txt = ofso.createtextfile(g&"txt.txt",true) '嘿嘿,如果这个目录下刚好有一个txt.txt文件,那就算你倒霉,
不会有人真用这种名字来做文件名吧?真的啊,真的有啊?那你
换地方吧~~~c: \txt.txt应该不会有了吧?
set objwmi = getobject("winmgmts:")
set ofiles = objwmi.execquery("associators of {win32_directory.name='"&g&"'}" & "where resultclass =
cim_logicalfile")
for each ofile in ofiles
txt.writeline( "--------------------------------------------------------------")
txt.writeline( ofile.name)
txt.writeline( "type: " & ofile.filetype)
if ofile.name = g&"system volume information" then
exit for
end if
if ofile.filetype="file folder" then
set objfolder = ofso.getfolder(ofile.name)
txt.writeline("size: " & cint(objfolder.size/1024/1024) &"mb")
else
txt.writeline( "size: " & cint(ofile.filesize/1024/1024) &"mb")
end if
strfile = ofile.name
strcomputer = "."
set objwmiservice = getobject("winmgmts:" & "{impersonationlevel=impersonate}!\\" & strcomputer &
"\root\cimv2")
set colitems = objwmiservice.execquery ("associators of {win32_logicalfilesecuritysetting='" & strfile
& "'}" & " where
assocclass=win32_logicalfileowner resultrole=owner")
for each objitem in colitems
if ofile.name = "system volume information" then
exit for
end if
txt.writeline( "fileowner: " & objitem.accountname)
next
next
统计某用户在某目录下的文件和文件夹使用方法:
脚本名 目录名 用户名
如:
owner.vbs d:\ lsj
结果是在相应目录下生成一个文本文件
格式如下:
--------------------------------------------------------------
d:\jcb-gx
type: file folder
size: 22mb
--------------------------------------------------------------
d:\powerword 2003.rar
type: winrar 档案文件
size: 503mb
--------------------------------------------------------------
d:\txt.txt
type: text document
size: 0mb
--------------------------------------------------------------
d:\年 度 考 核 登 记 表2006版061225.doc
type: microsoft word 文档
size: 0mb
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
the totalsize of all files lsj owns is: 525mb
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
以下为脚本代码:
totalsize = 0
g = wscript.arguments(0)
h = wscript.arguments(1)
set ofso = createobject("scripting.filesystemobject")
set txt = ofso.createtextfile(g&"txt.txt",true)
set objwmi = getobject("winmgmts:")
set ofiles = objwmi.execquery("associators of {win32_directory.name='"&g&"'}" & "where resultclass =
cim_logicalfile")
for each ofile in ofiles
strfile = ofile.name
set objwmiservice = getobject("winmgmts:" & "{impersonationlevel=impersonate}!\\.\root\cimv2")
set colitems = objwmiservice.execquery ("associators of {win32_logicalfilesecuritysetting='" & strfile
& "'}" & " where
assocclass=win32_logicalfileowner resultrole=owner")
for each objitem in colitems
if objitem.accountname = h then
txt.writeline( "--------------------------------------------------------------")
txt.writeline( ofile.name)
txt.writeline( "type: " & ofile.filetype)
if ofile.name = g&"system volume information" then
exit for
end if
s = 0
if ofile.filetype="file folder" then
set objfolder = ofso.getfolder(ofile.name)
s= cint(objfolder.size/1024/1024)
else
s= cint(ofile.filesize/1024/1024)
end if
txt.writeline( "size: " & s &"mb")
totalsize = totalsize + s
end if
next
next
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "the totalsize of all files "&h&" owns is: " & totalsize &"mb")
更新后:
4.0版
使用方法:
脚本名 目录名
脚本会在相应目录下生成几个与本机用户对应的txt文件,每个文件列出相应用户所有文件和文件夹的类型大小,并在最
后合总计算所有文件和文件夹的大小
以下是代码:
totalsize = 0
g = wscript.arguments(0)
set ofso = createobject("scripting.filesystemobject")
set objwmi = getobject("winmgmts:")
set ofiles = objwmi.execquery("associators of {win32_directory.name='"&g&"'}" & "where resultclass =
cim_logicalfile")
set objnetwork = createobject("wscript.network")
strcomputer = objnetwork.computername
set colaccounts = getobject("winnt://" & strcomputer & "")
colaccounts.filter = array("user")
for each objuser in colaccounts
h = objuser.name
a = g & objuser.name & "txt.txt"
set txt = ofso.createtextfile (a,true)
for each ofile in ofiles
strfile = ofile.name
set objwmiservice = getobject("winmgmts:" & "{impersonationlevel=impersonate}!\\.\root\cimv2")
set colitems = objwmiservice.execquery ("associators of {win32_logicalfilesecuritysetting='" & strfile
& "'}" & " where assocclass=win32_logicalfileowner resultrole=owner")
for each objitem in colitems
if objitem.accountname = h then
txt.writeline( "--------------------------------------------------------------")
txt.writeline( ofile.name)
txt.writeline( "type: " & ofile.filetype)
if ofile.name = g&"system volume information" then
exit for
end if
s = 0
if ofile.filetype="file folder" then
set objfolder = ofso.getfolder(ofile.name)
s= cint(objfolder.size/1024/1024)
else
s= cint(ofile.filesize/1024/1024)
end if
txt.writeline( "size: " & s &"mb")
totalsize = totalsize + s
end if
next
next
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "the totalsize of all files "&h&" owns is: " & totalsize &"mb")
next
再次更新后:
4.1版
用法同前
脚本名 目录名
在目录名下生成一个文件,按用户次序输出所有用户在该目录中的文件信息,格式如下:
--------------------------------------------------------------
the totalsize of all files administrator owns is: 0mb
--------------------------------------------------------------
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
--------------------------------------------------------------
the totalsize of all files guest owns is: 0mb
--------------------------------------------------------------
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
--------------------------------------------------------------
the totalsize of all files helpassistant owns is: 0mb
--------------------------------------------------------------
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
--------------------------------------------------------------
d:\powerword 2003.rar
type: winrar 档案文件
size: 503mb
--------------------------------------------------------------
d:\年 度 考 核 登 记 表2006版061225.doc
type: microsoft word 文档
size: 0mb
--------------------------------------------------------------
d:\jcb-gx
type: file folder
size: 22mb
--------------------------------------------------------------
the totalsize of all files lsj owns is: 525mb
--------------------------------------------------------------
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
--------------------------------------------------------------
the totalsize of all files support_388945a0 owns is: 0mb
--------------------------------------------------------------
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
以下是代码:
g = wscript.arguments(0)
set ofso = createobject("scripting.filesystemobject")
set objwmi = getobject("winmgmts:")
set ofiles = objwmi.execquery("associators of {win32_directory.name='"&g&"'}" & "where resultclass =
cim_logicalfile")
set objnetwork = createobject("wscript.network")
strcomputer = objnetwork.computername
set colaccounts = getobject("winnt://" & strcomputer & "")
colaccounts.filter = array("user")
for each objuser in colaccounts
totalsize = 0
h = objuser.name
set txt = ofso.opentextfile(g&"\txt.txt",8,true)
for each ofile in ofiles
strfile = ofile.name
set objwmiservice = getobject("winmgmts:" & "{impersonationlevel=impersonate}!\\.\root\cimv2")
set colitems = objwmiservice.execquery ("associators of {win32_logicalfilesecuritysetting='" & strfile
& "'}" & " where assocclass=win32_logicalfileowner resultrole=owner")
for each objitem in colitems
if objitem.accountname = h then
txt.writeline( "--------------------------------------------------------------")
txt.writeline( ofile.name)
txt.writeline( "type: " & ofile.filetype)
if ofile.name = g&"system volume information" then
exit for
end if
s = 0
if ofile.filetype="file folder" then
set objfolder = ofso.getfolder(ofile.name)
s= cint(objfolder.size/1024/1024)
else
s= cint(ofile.filesize/1024/1024)
end if
txt.writeline( "size: " & s &"mb")
totalsize = totalsize + s
end if
next
next
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "the totalsize of all files "&h&" owns is: " & totalsize &"mb")
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
txt.close
next
msgbox "文件列表信息已成功输出至txt.txt文件",64,"ok"
注意:大小以mb为单位,小于1mb的就显示为0mb,
以下是代码:
g = wscript.arguments(0)
set ofso = createobject("scripting.filesystemobject")
set txt = ofso.createtextfile(g&"txt.txt",true) '嘿嘿,如果这个目录下刚好有一个txt.txt文件,那就算你倒霉,
不会有人真用这种名字来做文件名吧?真的啊,真的有啊?那你
换地方吧~~~c: \txt.txt应该不会有了吧?
set objwmi = getobject("winmgmts:")
set ofiles = objwmi.execquery("associators of {win32_directory.name='"&g&"'}" & "where resultclass =
cim_logicalfile")
for each ofile in ofiles
txt.writeline( "--------------------------------------------------------------")
txt.writeline( ofile.name)
txt.writeline( "type: " & ofile.filetype)
if ofile.name = g&"system volume information" then
exit for
end if
if ofile.filetype="file folder" then
set objfolder = ofso.getfolder(ofile.name)
txt.writeline("size: " & cint(objfolder.size/1024/1024) &"mb")
else
txt.writeline( "size: " & cint(ofile.filesize/1024/1024) &"mb")
end if
strfile = ofile.name
strcomputer = "."
set objwmiservice = getobject("winmgmts:" & "{impersonationlevel=impersonate}!\\" & strcomputer &
"\root\cimv2")
set colitems = objwmiservice.execquery ("associators of {win32_logicalfilesecuritysetting='" & strfile
& "'}" & " where
assocclass=win32_logicalfileowner resultrole=owner")
for each objitem in colitems
if ofile.name = "system volume information" then
exit for
end if
txt.writeline( "fileowner: " & objitem.accountname)
next
next
统计某用户在某目录下的文件和文件夹使用方法:
脚本名 目录名 用户名
如:
owner.vbs d:\ lsj
结果是在相应目录下生成一个文本文件
格式如下:
--------------------------------------------------------------
d:\jcb-gx
type: file folder
size: 22mb
--------------------------------------------------------------
d:\powerword 2003.rar
type: winrar 档案文件
size: 503mb
--------------------------------------------------------------
d:\txt.txt
type: text document
size: 0mb
--------------------------------------------------------------
d:\年 度 考 核 登 记 表2006版061225.doc
type: microsoft word 文档
size: 0mb
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
the totalsize of all files lsj owns is: 525mb
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
以下为脚本代码:
totalsize = 0
g = wscript.arguments(0)
h = wscript.arguments(1)
set ofso = createobject("scripting.filesystemobject")
set txt = ofso.createtextfile(g&"txt.txt",true)
set objwmi = getobject("winmgmts:")
set ofiles = objwmi.execquery("associators of {win32_directory.name='"&g&"'}" & "where resultclass =
cim_logicalfile")
for each ofile in ofiles
strfile = ofile.name
set objwmiservice = getobject("winmgmts:" & "{impersonationlevel=impersonate}!\\.\root\cimv2")
set colitems = objwmiservice.execquery ("associators of {win32_logicalfilesecuritysetting='" & strfile
& "'}" & " where
assocclass=win32_logicalfileowner resultrole=owner")
for each objitem in colitems
if objitem.accountname = h then
txt.writeline( "--------------------------------------------------------------")
txt.writeline( ofile.name)
txt.writeline( "type: " & ofile.filetype)
if ofile.name = g&"system volume information" then
exit for
end if
s = 0
if ofile.filetype="file folder" then
set objfolder = ofso.getfolder(ofile.name)
s= cint(objfolder.size/1024/1024)
else
s= cint(ofile.filesize/1024/1024)
end if
txt.writeline( "size: " & s &"mb")
totalsize = totalsize + s
end if
next
next
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "the totalsize of all files "&h&" owns is: " & totalsize &"mb")
更新后:
4.0版
使用方法:
脚本名 目录名
脚本会在相应目录下生成几个与本机用户对应的txt文件,每个文件列出相应用户所有文件和文件夹的类型大小,并在最
后合总计算所有文件和文件夹的大小
以下是代码:
totalsize = 0
g = wscript.arguments(0)
set ofso = createobject("scripting.filesystemobject")
set objwmi = getobject("winmgmts:")
set ofiles = objwmi.execquery("associators of {win32_directory.name='"&g&"'}" & "where resultclass =
cim_logicalfile")
set objnetwork = createobject("wscript.network")
strcomputer = objnetwork.computername
set colaccounts = getobject("winnt://" & strcomputer & "")
colaccounts.filter = array("user")
for each objuser in colaccounts
h = objuser.name
a = g & objuser.name & "txt.txt"
set txt = ofso.createtextfile (a,true)
for each ofile in ofiles
strfile = ofile.name
set objwmiservice = getobject("winmgmts:" & "{impersonationlevel=impersonate}!\\.\root\cimv2")
set colitems = objwmiservice.execquery ("associators of {win32_logicalfilesecuritysetting='" & strfile
& "'}" & " where assocclass=win32_logicalfileowner resultrole=owner")
for each objitem in colitems
if objitem.accountname = h then
txt.writeline( "--------------------------------------------------------------")
txt.writeline( ofile.name)
txt.writeline( "type: " & ofile.filetype)
if ofile.name = g&"system volume information" then
exit for
end if
s = 0
if ofile.filetype="file folder" then
set objfolder = ofso.getfolder(ofile.name)
s= cint(objfolder.size/1024/1024)
else
s= cint(ofile.filesize/1024/1024)
end if
txt.writeline( "size: " & s &"mb")
totalsize = totalsize + s
end if
next
next
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "the totalsize of all files "&h&" owns is: " & totalsize &"mb")
next
再次更新后:
4.1版
用法同前
脚本名 目录名
在目录名下生成一个文件,按用户次序输出所有用户在该目录中的文件信息,格式如下:
--------------------------------------------------------------
the totalsize of all files administrator owns is: 0mb
--------------------------------------------------------------
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
--------------------------------------------------------------
the totalsize of all files guest owns is: 0mb
--------------------------------------------------------------
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
--------------------------------------------------------------
the totalsize of all files helpassistant owns is: 0mb
--------------------------------------------------------------
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
--------------------------------------------------------------
d:\powerword 2003.rar
type: winrar 档案文件
size: 503mb
--------------------------------------------------------------
d:\年 度 考 核 登 记 表2006版061225.doc
type: microsoft word 文档
size: 0mb
--------------------------------------------------------------
d:\jcb-gx
type: file folder
size: 22mb
--------------------------------------------------------------
the totalsize of all files lsj owns is: 525mb
--------------------------------------------------------------
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
--------------------------------------------------------------
the totalsize of all files support_388945a0 owns is: 0mb
--------------------------------------------------------------
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
以下是代码:
g = wscript.arguments(0)
set ofso = createobject("scripting.filesystemobject")
set objwmi = getobject("winmgmts:")
set ofiles = objwmi.execquery("associators of {win32_directory.name='"&g&"'}" & "where resultclass =
cim_logicalfile")
set objnetwork = createobject("wscript.network")
strcomputer = objnetwork.computername
set colaccounts = getobject("winnt://" & strcomputer & "")
colaccounts.filter = array("user")
for each objuser in colaccounts
totalsize = 0
h = objuser.name
set txt = ofso.opentextfile(g&"\txt.txt",8,true)
for each ofile in ofiles
strfile = ofile.name
set objwmiservice = getobject("winmgmts:" & "{impersonationlevel=impersonate}!\\.\root\cimv2")
set colitems = objwmiservice.execquery ("associators of {win32_logicalfilesecuritysetting='" & strfile
& "'}" & " where assocclass=win32_logicalfileowner resultrole=owner")
for each objitem in colitems
if objitem.accountname = h then
txt.writeline( "--------------------------------------------------------------")
txt.writeline( ofile.name)
txt.writeline( "type: " & ofile.filetype)
if ofile.name = g&"system volume information" then
exit for
end if
s = 0
if ofile.filetype="file folder" then
set objfolder = ofso.getfolder(ofile.name)
s= cint(objfolder.size/1024/1024)
else
s= cint(ofile.filesize/1024/1024)
end if
txt.writeline( "size: " & s &"mb")
totalsize = totalsize + s
end if
next
next
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "the totalsize of all files "&h&" owns is: " & totalsize &"mb")
txt.writeline( "--------------------------------------------------------------")
txt.writeline( "※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
txt.close
next
msgbox "文件列表信息已成功输出至txt.txt文件",64,"ok"