VBS lists the types, sizes, and owner _vbs of all files and folders under this directory

Source: Internet
Author: User
Tags rar
Getowner.vbs usage, at the command line: The Getowner.vbs directory name generates a TXT.TXT file in the corresponding directory, listing the type, size, and owner of all files and folders under that directory.
Note: The size in megabytes, less than 1MB is displayed as 0MB,

Here's the code:

G = wscript.arguments (0)
Set oFSO = CreateObject ("Scripting.FileSystemObject")
Set txt = ofso.createtextfile (g& "TXT.txt", true) ' Hey, if there's a TXT.txt file under this directory, that's bad luck,
No one is really using this name to do the file name, right? Oh, really? then you
Change place. ~~~c: \txt. TXT should not have it?
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

To count the ways in which a user uses files and folders in a directory:
Script Name Directory name User name
Such as:
Owner.vbs D:\ LSJ
The result is that a text file is generated in the appropriate directory
The format is as follows:
--------------------------------------------------------------
D:\jcb-gx
Type:file Folder
Size:22mb
--------------------------------------------------------------
D:\powerword 2003.rar
Type:winrar Archive File
Size:503mb
--------------------------------------------------------------
D:\txt.txt
Type:text Document
size:0mb
--------------------------------------------------------------
D:\ Annual Examination Registration Form 2006 Version 061225.doc
Type:microsoft Word Document
size:0mb
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
The totalsize of all files LSJ owns IS:525MB
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here's the scripting code:

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 are:" & totalsize & "MB")

After the update:
Version 4.0
How to use:
Script Name Directory name
The script will generate several TXT files corresponding to the native user in the corresponding directory, each file lists the type size of all files and folders of the corresponding user, and at the most
Always calculates the size of all files and folders
Here's the code:

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 are:" & totalsize & "MB")
Next

After updating again:
Version 4.1
Usage Previous
Script Name Directory name
Generates a file in the directory name, outputting all the user's file information in the directory in user order, in the following format:
--------------------------------------------------------------
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 Archive File
Size:503mb
--------------------------------------------------------------
D:\ Annual Examination Registration Form 2006 Version 061225.doc
Type:microsoft Word Document
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
--------------------------------------------------------------
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※

Here's the code:

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 are:" & totalsize & "MB")
Txt. WriteLine ("--------------------------------------------------------------")
Txt. WriteLine ("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
Txt. Close
Next
MsgBox "File list information has been successfully exported to TXT.TXT file", "OK"

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.