vbs 列出该目录下所有文件和文件夹的类型,大小,和所有者

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"

(0)

相关推荐

  • vbs 列出该目录下所有文件和文件夹的类型,大小,和所有者

    GetOwner.VBS用法,在命令行下:GetOwner.vbs 目录名会在相应目录下生成一个TXT.TXT文件,内里列出该目录下所有文件和文件夹的类型,大小,和所有者 注意:大小以MB为单位,小于1MB的就显示为0MB, 以下是代码: G = WScript.arguments(0) Set oFSO = CreateObject("Scripting.FileSystemObject") set txt = oFSO.CreateTextFile(G&"TXT.

  • php列出一个目录下的所有文件的代码

    复制代码 代码如下: <?php function dir_path($path) { $path = str_replace('\\', '/', $path); if (substr($path, -1) != '/') $path = $path . '/'; return $path; } /** * 列出目录下的所有文件 * * @param str $path 目录 * @param str $exts 后缀 * @param array $list 路径数组 * @return a

  • MySQL 5.7.19安装目录下创建my.ini文件的方法

    在上篇文章给大家介绍了Mysql 5.7.19 免安装版配置方法教程详解(64位),本文重点给大家介绍MySQL 5.7.19安装目录下创建my.ini文件的方法,大家可以参考下. 基本内容如下 [mysqld] character-set-server=utf8 #绑定IPv4和3306端口 bind-address = 0.0.0.0 port = 3306 # 设置mysql的安装目录 basedir=F:/test/mysql-5.7.19-winx64 # 设置mysql数据库的数据的

  • python读取目录下所有的jpg文件,并显示第一张图片的示例

    如下所示: # -*- coding: UTF-8 -*- import numpy as np import os from scipy.misc import imread, imresize import matplotlib.pyplot as plt from glob import glob # 读取目录下所有的jpg图片 def load_image(image_path, image_size): file_name=glob(image_path+"/*jpg") s

  • 解决Centos7安装nginx后提示“Welcome to nginx on Fedora!”,conf.d目录下无default.conf文件

    问题描述 在腾讯云centos7上安装nginx sudo yum install nginx 打开默认网页显示 Welcome to nginx on Fedora! 且 /etc/nginx/conf.d 目录下无default.conf文件 原因 腾讯云的epel源是默认下载就是Fedora的 解决方法 •准备工作 sudo yum install yum-utils •创建nginx.repo文件 sudo vim /etc/yum.repos.d/nginx.repo 并添加以下内容

  • Java使用FilenameFilter查找出目录下指定后缀的文件示例

    本文实例讲述了Java使用FilenameFilter查找出目录下指定后缀的文件.分享给大家供大家参考,具体如下: 在项目中需要查找指定目录下特定后缀的文件,在jdk官网上查看资料时找到了FilenameFilter这个类,怎么用也写了,但是就是没给个例子,对有些人实在有些不方便,这也是写这篇文章的初衷,虽然简单但希望能帮到需要的小伙伴们 下面直接入正题,给出demo程序: package net.csdn.johnhuster; import java.io.File; import java

  • 解决pycharm同一目录下无法import其他文件

    如图:会出现带有红色波浪线,但是确实有random_walk文件 解决方法: 在当前文件下,右键找到mark Directory as 然后选择source root,完工ok 再如图: 以上这篇解决pycharm同一目录下无法import其他文件就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们.

  • Python实现扫描指定目录下的子目录及文件的方法

    本文介绍了使用Python来扫描指定目录下的文件,或者匹配指定后缀和前缀的函数.步骤如下: 如果要扫描指定目录下的文件,包括子目录,需要调用scan_files("/export/home/test/") 如果要扫描指定目录下的特定后缀的文件(比如jar包),包括子目录,调用scan_files("/export/home/test/", postfix=".jar") 如果要扫描指定目录下的特定前缀的文件(比如test_xxx.py),包括子目

  • 列出指定目录下的所有文件和目录

    <%@ LANGUAGE = VBScript %> <%Server.ScriptTimeout=5000%> <html> <head> <style TYPE="text/css"> /* Outline Style Sheet */ UL UL {display: none; margin-left: 20pt} </style> <script LANGUAGE="JavaScript&q

  • C# 遍历文件夹子目录下所有图片及遍历文件夹下的文件

    要求:取指定目录下面的所有图片,以表格的型式展示并显示该图片的相对路径. 服务端代码: public partial class ViewIcon : System.Web.UI.Page { JArray ja = new JArray(); //定义一个数组 public string info = string.Empty; protected void Page_Load(object sender, EventArgs e) { var path1 = System.AppDomain

随机推荐