189 8069 5689

vbsTreeVBS脚本怎么模拟tree命令-创新互联

这篇文章主要介绍“vbsTree VBS脚本怎么模拟tree命令”,在日常操作中,相信很多人在vbsTree VBS脚本怎么模拟tree命令问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”vbsTree VBS脚本怎么模拟tree命令”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

创新互联建站坚信:善待客户,将会成为终身客户。我们能坚持多年,是因为我们一直可值得信赖。我们从不忽悠初访客户,我们用心做好本职工作,不忘初心,方得始终。10余年网站建设经验创新互联建站是成都老牌网站营销服务商,为您提供网站制作、网站设计、网站设计、html5、网站制作、品牌网站制作、小程序定制开发服务,给众多知名企业提供过好品质的建站服务。

复制代码 代码如下:


'-------------vbsTree.vbs------------------------
'描述:用vbs输出一个文件夹的目录结构。
'------------------------------------------------
Const Unit4Size = "字节KBMBGB"
Const OutFile = "OutTree.txt"
Dim theApp,SelPath,TreePath,TreeStr
Set theApp = CreateObject("Shell.Application")
Set SelPath = theApp.BrowseForFolder(0,"请选择需要列出子项目的路径",0)
If SelPath Is Nothing Then WScript.Quit
TreePath = SelPath.items.Item.Path
Set SelPathPath = Nothing
Set theApp = Nothing
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
TreeStr = TreePath & FormatSize(objFSO.GetFolder(TreePath).Size) & vbCrLf
Tree TreePath,""
Set objFile = objFSO.CreateTextFile(OutFile,True)
objFile.Write TreeStr
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
MsgBox "查看当前目录下的OutTree.txt",vbInformation,"完成 - vbsTree"
Sub Tree(Path,SFSpace)
Dim i,TempStr,FlSpace
FlSpace = SFSpace & " "
Set CrntFolder = objFSO.GetFolder(Path)
i = 0:TempStr = "├─"
For Each ConFile In CrntFolder.Files
i = i + 1
If i = CrntFolder.Files.Count And CrntFolder.SubFolders.Count = 0 Then TempStr = "└─"
TreeStr = TreeStr & FlSpace & Tempstr & ConFile.name & FormatSize(ConFile.size) & vbCrLf
Next
i = 0:TempStr = "├─"
For Each SubFolder In CrntFolder.SubFolders
i = i + 1
If i = CrntFolder.SubFolders.Count Then
TempStr = "└─"
SFSpace = FlSpace & " "
Else
SFSpace = FlSpace & "│"
End If
TreeStr = TreeStr & FlSpace & TempStr & SubFolder.name & FormatSize(SubFolder.size) & vbCrLf
Tree SubFolder,(SFSpace)
Next
End Sub
Function FormatSize(SZ)
Dim i
Do While SZ > 1024
i = i + 1
SZ = SZ \ 1024
Loop
FormatSize = " (" & SZ & Mid(Unit4Size,1 + 2 * i,2) & ")"
End Function



文件夹浏览部分优化后的代码


复制代码 代码如下:


'-------------vbsTree.vbs------------------------
'描述:用vbs输出一个文件夹的目录结构。
'------------------------------------------------
Const Unit4Size = "字节KBMBGB"
Const OutFile = "OutTree.txt"
Dim TreePath,TreeStr,WS
Set WS = WScript.CreateObject("WScript.Shell")
TreePath = BFF("请选择需要列出子项目的路径",&H0001 + &H0008 + &H0010,"")
Set WS = Nothing
If Len(TreePath) = 0 Then WScript.Quit
If Len(TreePath) <= 3 Then MsgBox "无法处理根目录!",64,"提示":WScript.Quit

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
TreeStr = TreePath & FormatSize(objFSO.GetFolder(TreePath).Size) & vbCrLf
Tree TreePath,""
Set objFile = objFSO.CreateTextFile(OutFile,True)
objFile.Write TreeStr
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
MsgBox "查看当前目录下的OutTree.txt",vbInformation,"完成 - vbsTree"
Sub Tree(Path,SFSpace)
Dim i,TempStr,FlSpace
FlSpace = SFSpace & " "
Set CrntFolder = objFSO.GetFolder(Path)
i = 0:TempStr = "├─"
For Each ConFile In CrntFolder.Files
i = i + 1
If i = CrntFolder.Files.Count And CrntFolder.SubFolders.Count = 0 Then TempStr = "└─"
TreeStr = TreeStr & FlSpace & Tempstr & ConFile.name & FormatSize(ConFile.size) & vbCrLf
Next
i = 0:TempStr = "├─"
For Each SubFolder In CrntFolder.SubFolders
i = i + 1
If i = CrntFolder.SubFolders.Count Then
TempStr = "└─"
SFSpace = FlSpace & " "
Else
SFSpace = FlSpace & "│"
End If
TreeStr = TreeStr & FlSpace & TempStr & SubFolder.name & FormatSize(SubFolder.size) & vbCrLf
Tree SubFolder,(SFSpace)
Next
End Sub
Function FormatSize(SZ)
Dim i
Do While SZ > 1024
i = i + 1
SZ = SZ \ 1024
Loop
FormatSize = " (" & SZ & Mid(Unit4Size,1 + 2 * i,2) & ")"
End Function


Function BFF(title, flag, dir)
On Error Resume Next
Dim oShell, oItem, oStr
Set oShell = WScript.CreateObject("Shell.Application")
Set oItem = oShell.BrowseForFolder(&H0, title, flag, dir)
oStr = oItem.Title
If Err <> 0 Then
Set oShell = Nothing
Set oItem = Nothing
Exit Function
End If

If InStr(oStr, ":") Then
BFF = mid(oStr,InStr(oStr, ":")-1, 2)
Else
Select Case oStr
Case "桌面"
BFF = WS.SpecialFolders("Desktop")
Case "我的文档"
BFF = WS.SpecialFolders("MyDocuments")
Case "我的电脑"
MsgBox "无效目录!",64,"提示":WScript.Quit
Case "网上邻居"
MsgBox "无效目录!",64,"提示":WScript.Quit
Case Else
BFF = oItem.ParentFolder.ParseName(oItem.Title).Path
End Select
End If
Set oShell = Nothing
Set oItem = Nothing
If Right(BFF,1)<> "\" Then
BFF = BFF & "\"
End If
On Error GoTo 0
End Function


到此,关于“vbsTree VBS脚本怎么模拟tree命令”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!


文章名称:vbsTreeVBS脚本怎么模拟tree命令-创新互联
网页地址:http://cdxtjz.cn/article/djggip.html

其他资讯