中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-12 13:38
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » [Original] vbs version of Tree
Printable Version  2,831 / 23
Floor1 slore Posted 2008-12-26 20:23
铂金会员 Posts 2,478 Credits 5,212
Not sure whether to post it or not.



'-------------vbsTree.vbs------------------------
'Description: Output the directory structure of a folder using vbs.
' By Slore @ 2008-12-26
'------------------------------------------------

Const Unit4Size = "字节KBMBGB"
Const OutFile = "OutTree.txt"

Dim theApp, SelPath, TreePath, TreeStr

Set theApp = CreateObject("Shell.Application")
Set SelPath = theApp.BrowseForFolder(0, "Please select the path for which you need to list sub-items", 0)
If SelPath Is Nothing Then WScript.Quit
TreePath = SelPath.items.Item.Path
Set SelPathPath = Nothing
Set theApp = Nothing

Dim ShowSize
ShowSize = MsgBox("Do you need to display the size?", vbYesNo, "vbsTree By Slore") - 7

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
TreeStr = TreePath
On Error Resume Next 'Fault-tolerant mode (ignore special folder errors)
If ShowSize Then TreeStr = TreeStr & FormatSize(objFSO.GetFolder(TreePath).Size)
TreeStr = TreeStr & vbCrLf
starttime = Timer
Tree TreePath, ""
endtime = Timer
Set objFile = objFSO.CreateTextFile(OutFile, True)
objFile.Write TreeStr
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
tottime = endtime - starttime
tottime = FormatNumber(tottime, 3, True) & " seconds"
MsgBox "Please check OutTree.txt in the current directory" & vbCrLf & "Time used: " & tottime, vbInformation, "Completed - 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
If ShowSize Then TreeStr = TreeStr & FormatSize(ConFile.Size)
TreeStr = TreeStr & vbCrLf
Next
i = 0: TempStr = "├─"
SFSpace = FlSpace & "│"
For Each SubFolder In CrntFolder.SubFolders
i = i + 1
If i = CrntFolder.SubFolders.Count Then
TempStr = "└─"
SFSpace = FlSpace & " "
End If
TreeStr = TreeStr & FlSpace & TempStr & SubFolder.Name
If ShowSize Then TreeStr = TreeStr & FormatSize(SubFolder.size)
TreeStr = TreeStr & 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





E:\IconWorkShop (11MB)
├─axlibico.dll (383KB)
├─Axstdctl.dll (18KB)
├─Context.hlp (68KB)
├─IconWorkshop.exe (5MB)
├─Main.chm (4MB)
├─MediaFiles.axd (4KB)
├─ResChs.dll (388KB)
├─sn.txt (32 bytes)
├─UnInstall.exe (74KB)
├─UnInstall.ini (109 bytes)
├─Color Swatches (54KB)
│ ├─16 Colors (extended).axco (1KB)
│ ├─16 Colors.axco (343 bytes)
│ ├─Dark Hues.axco (3KB)
│ ├─Default (large).axco (6KB)
│ ├─Default (small).axco (3KB)
│ ├─Grayscale (128 levels).axco (1KB)
│ ├─Grayscale (256 levels).axco (3KB)
│ ├─IconWorkshopSwatches (3KB)
│ ├─Medium Hues.axco (3KB)
│ ├─Pastel Hues.axco (3KB)
│ ├─Photoshop Default.axco (1KB)
│ ├─Pure Hues.axco (3KB)
│ ├─Spectrum (variable lightness).axco (6KB)
│ ├─Spectrum (variable saturation).axco (6KB)
│ ├─Spectrum.axco (3KB)
│ ├─Web Safe by VisiBone.axco (3KB)
│ ├─Web Safe.axco (2KB)
│ └─Windows XP.axco (376 bytes)
└─Color Tables (3KB)
├─IconWorkshop Standard.axct (768 bytes)
├─Macintosh.axct (768 bytes)
├─Web Safe.axct (768 bytes)
├─Windows XP.axct (768 bytes)
└─Windows.axct (768 bytes)



[ Last edited by slore on 2008-12-26 at 20:25 ]
Floor2 holucan Posted 2008-12-26 21:25
初级用户 Posts 25 Credits 26
, Oh, thank you for sharing, I'll take it and study it. I tried it out, and it's pretty good!
Floor3 oceanuse Posted 2008-12-27 15:18
新手上路 Posts 15 Credits 18
Thanks for sharing.
Output the directory structure of a folder.
It would be even better if you can output the directory structure of the disk root directory (such as E:\). Currently, it can only output the file directory in E:\ and cannot output the secondary directory structure.
Floor4 slore Posted 2008-12-27 16:02
铂金会员 Posts 2,478 Credits 5,212
The test can be output. But mine is NTFS, some folder permissions are set, and it terminates when it can't get the permissions, but it can get it.

For the disk, the disk size can't be obtained because it's using the size of the folder instead of the driver.

[ Last edited by HAT on 2009-1-2 at 21:28 ]
Floor5 523066680 Posted 2009-01-02 15:55
银牌会员 Posts 1,133 Credits 2,362

S smile 微笑, L love 爱, O optimism 乐观, R relax 放松, E enthusiasm 热情... Slore

This is a water post, I thought of something

W smile A love L optimism F relax R enthusiasm
Walfr

Just not as elegant as Slore
Floor6 s11ss Posted 2009-01-02 19:46
银牌会员 Posts 566 Credits 2,098
Originally posted by 523066680 at 2009-1-2 03:55 PM:

This is a water post, I thought of something

W for smile, A for love, L for optimism, F for relaxation, R for enthusiasm
Walfr

Just not as fancy as slore :(

Walfr doesn't look like an English word at all. Where is there a word ending with fr? At least I haven't seen any.
Floor7 slore Posted 2009-01-02 21:13
铂金会员 Posts 2,478 Credits 5,212
I'm郁闷...
Don't have edit privileges... That didn't expect it to be that long...

HAT saw and deleted that code segment for drive traversal =. =

Hehe, that means first there's Slore and then looking for it, so it's easy to find.
Floor8 HAT Posted 2009-01-02 21:28
版主 Posts 5,017 Credits 9,023
Floor9 kioskboy Posted 2009-01-03 14:09
初级用户 Posts 103 Credits 153
Good
Floor10 ooaf Posted 2009-01-04 23:19
中级用户 Posts 162 Credits 313
There is a problem on my computer

Attachments
未命名.bmp (7.98 KiB)
Floor11 slore Posted 2009-01-05 13:42
铂金会员 Posts 2,478 Credits 5,212
Are you selecting a folder?
Floor12 ooaf Posted 2009-01-05 21:40
中级用户 Posts 162 Credits 313
"Desktop", is there a problem?
Floor13 slore Posted 2009-01-06 12:23
铂金会员 Posts 2,478 Credits 5,212
That returns a special folder number. Someone else has modified it to support that kind, but mine is not processed in the original version. You can just expand and select it on my computer...
Floor14 ouyang0349 Posted 2010-03-27 09:33
新手上路 Posts 9 Credits 9
I have tested here that only part of the directories can be listed, and many cannot be listed. What's the matter?
Floor15 ouyang0349 Posted 2010-03-27 10:00
新手上路 Posts 9 Credits 9
I use this script to list the directory tree of all files and folders on drive E. There are many files on drive E, and it can only list the first four folders and the directory structure, and the following ones cannot be listed. What's the matter?
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023