China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-27 03:30
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] vbs version of Tree View 2,629 Replies 23
Original Poster Posted 2008-12-26 20:23 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
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 ]
Recent Ratings for This Post ( 5 in total) Click for details
RaterScoreTime
HAT +12 2008-12-26 23:14
moniuming +11 2008-12-27 10:06
523066680 +7 2008-12-27 17:21
newxso +2 2008-12-29 10:24
ooaf +4 2009-01-05 23:35
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 2 Posted 2008-12-26 21:25 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 26
Posts 25
Joined 2008-11-07 16:06
17-year member
UID 130293
Gender Male
Status Offline
, Oh, thank you for sharing, I'll take it and study it. I tried it out, and it's pretty good!
Floor 3 Posted 2008-12-27 15:18 ·  美国 加利福尼亚州 橙 布雷亚 DreamHost公司
新手上路
Credits 18
Posts 15
Joined 2007-03-25 08:21
19-year member
UID 82858
Gender Male
Status Offline
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.
Floor 4 Posted 2008-12-27 16:02 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
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 ]
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 5 Posted 2009-01-02 15:55 ·  中国 广东 揭阳 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline

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
Floor 6 Posted 2009-01-02 19:46 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
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.
Floor 7 Posted 2009-01-02 21:13 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
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.
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 8 Posted 2009-01-02 21:28 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Floor 9 Posted 2009-01-03 14:09 ·  中国 广东 深圳 电信
初级用户
★★
Credits 153
Posts 103
Joined 2008-03-27 19:38
18-year member
UID 114210
Gender Male
Status Offline
Good
Floor 10 Posted 2009-01-04 23:19 ·  中国 北京 联通
中级用户
★★
Credits 313
Posts 162
Joined 2007-04-02 06:45
19-year member
UID 83693
Gender Male
Status Offline
There is a problem on my computer
Attachments
未命名.bmp
Floor 11 Posted 2009-01-05 13:42 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Are you selecting a folder?
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 12 Posted 2009-01-05 21:40 ·  中国 北京 联通
中级用户
★★
Credits 313
Posts 162
Joined 2007-04-02 06:45
19-year member
UID 83693
Gender Male
Status Offline
"Desktop", is there a problem?
Floor 13 Posted 2009-01-06 12:23 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
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...
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 14 Posted 2010-03-27 09:33 ·  中国 天津 电信
新手上路
Credits 9
Posts 9
Joined 2010-03-26 15:03
16-year member
UID 163096
Gender Male
Status Offline
I have tested here that only part of the directories can be listed, and many cannot be listed. What's the matter?
Floor 15 Posted 2010-03-27 10:00 ·  中国 天津 电信
新手上路
Credits 9
Posts 9
Joined 2010-03-26 15:03
16-year member
UID 163096
Gender Male
Status Offline
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?
Forum Jump: