In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you the "vbs how to list the type, size, and owner of all files and folders in this directory", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "vbs how to list the type, size, and owner of all files and folders in this directory" this article.
GetOwner.VBS usage, under the command line: the GetOwner.vbs directory name generates a TXT.TXT file in the corresponding directory that lists the type, size, and owner of all files and folders in that directory
Note: the size is in MB, and less than 1MB is displayed as 0MB.
Here is the code:
G = WScript.arguments (0)
Set oFSO = CreateObject ("Scripting.FileSystemObject")
Set txt = oFSO.CreateTextFile (G & "TXT.txt", true) 'Hey hey, if there happens to be a TXT.txt file in this directory, that's your bad luck.
No one would really use that name as a file name, would it? Really, really? You
Let's go somewhere else. C:\ TXT.TXT shouldn't have it, will 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
Count the usage of a user's files and folders in a directory:
Script name directory name user name
Such as:
Owner.vbs d:\ lsj
The result is to generate a text file in the corresponding 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
~
The following is the script 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 is:" & TotalSize & "MB")
After update:
Version 4.0
How to use it:
Script name directory name
The script generates several TXT files corresponding to the local user in the appropriate directory, each listing the type and size of all files and folders for the corresponding user, and in the most
Then the total calculates the size of all files and folders.
Here is 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 real 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
After updating again:
Version 4.1
Usage is the same as before
Script name directory name
Generate a file under the directory name and output the file information of all users in that directory in user order in the following format:
The TotalSize of All files Administrator owns is: 0MB
Cymbals
The TotalSize of All files Guest owns is: 0MB
Cymbals
The TotalSize of All files HelpAssistant owns is: 0MB
Cymbals
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
Cymbals
The TotalSize of All files SUPPORT_388945a0 owns is: 0MB
Cymbals
Here is 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", 8Jing 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 ("customers")
TXT.Close
Next
MsgBox "File list information successfully output to TXT.TXT file", 64, "OK"
The above is all the contents of the article "how vbs lists the type, size, and owner of all files and folders in this directory". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.