本帖最后由 pcl_test 于 2016-11-4 22:00 编辑
vbs,修改自http://www.bathome.net/viewthread.php?tid=2914- Set fso = CreateObject("Scripting.FileSystemObject")
- TreePath = "." '指定文件夹/目录路径,默认为当前文件夹/目录
- OutFile = "OutTree.txt"
-
- If TreePath = "." Then Set TreePath = fso.GetFolder(".")
- fs = 0:For Each f In TreePath.Files
- fs = fs+f.size
- Next
- TreeStr = TreePath.path & " (" & TreePath.SubFolders.Count & _
- " folders, "& TreePath.Files.Count &" files, "&FormatSize(fs) & _
- ", "& FormatSize(TreePath.Size) & " in total.)" & vbCrLf
- Tree TreePath.path,""
- fso.CreateTextFile(OutFile, True).Write TreeStr
- MsgBox "查看当前目录下的OutTree.txt",vbInformation,"完成 - vbsTree"
-
- Sub Tree(Path,SFSpace)
- Dim i,TempStr,FlSpace,fsize
- FlSpace = SFSpace & " "
- Set CrntFolder = fso.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
- fsize = 0:i = i + 1
- If i = CrntFolder.SubFolders.Count Then
- TempStr = "└─"
- SFSpace = FlSpace & " "
- Else
- SFSpace = FlSpace & "│"
- End If
- For Each f In SubFolder.Files
- fsize = fsize+f.size
- Next
- TreeStr = TreeStr & FlSpace & TempStr & SubFolder.name & " (" & SubFolder.SubFolders.Count & _
- " folders, "& SubFolder.Files.Count &" files, "& FormatSize(fsize) & _
- ", "& FormatSize(SubFolder.size) & " in total.)" & vbCrLf
- Tree SubFolder,(SFSpace)
- Next
- End Sub
-
- Function FormatSize(size)
- If size >= 1099511627776 Then
- FormatSize = FormatNumber(size/1099511627776, 2, true) & " TB"
- ElseIf size >= 1073741824 Then
- FormatSize = FormatNumber(size/1073741824, 2, true) & " GB"
- ElseIf size >= 1048576 Then
- FormatSize = FormatNumber(size/1048576, 2, true) & " MB"
- ElseIf size >= 1024 Then
- FormatSize = FormatNumber(size/1024, 2, true) & " KB"
- Else
- FormatSize = size & " Bytes"
- End If
- End Function
复制代码
|