中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》
  • 首頁 > 
  • 教程 > 
  • 開發技術 > 
  • vbs如何列出該目錄下所有文件和文件夾的類型,大小,和所有者

vbs如何列出該目錄下所有文件和文件夾的類型,大小,和所有者

發布時間:2021-10-12 10:50:45 來源:億速云 閱讀:241 作者:小新 欄目:開發技術

這篇文章主要為大家展示了“vbs如何列出該目錄下所有文件和文件夾的類型,大小,和所有者”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“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"

以上是“vbs如何列出該目錄下所有文件和文件夾的類型,大小,和所有者”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

vbs
AI

囊谦县| 舟山市| 资溪县| 兴业县| 揭阳市| 法库县| 龙陵县| 上林县| 军事| 江永县| 南皮县| 类乌齐县| 辽中县| 扶沟县| 白玉县| 丹凤县| 扎赉特旗| 通山县| 日喀则市| 焉耆| 武汉市| 南江县| 沂南县| 邵阳市| 延津县| 修水县| 武川县| 仁怀市| 铜山县| 兰西县| 金阳县| 龙泉市| 潼关县| 蕲春县| 沛县| 六枝特区| 吕梁市| 曲麻莱县| 伊金霍洛旗| 汶川县| 白银市|