标题: [文件操作] 批处理如何获取当前目录下所有子文件夹和文件的名称及大小并以树形结构输出? [打印本页]
作者: fwy12 时间: 2016-11-4 08:24 标题: 批处理如何获取当前目录下所有子文件夹和文件的名称及大小并以树形结构输出?
本帖最后由 pcl_test 于 2016-11-4 11:08 编辑
请问下如何获取目录下所有的子目录名及文件名和大小?
就是输出如下格式的文件。
不知道这个用批能不能处理好。
谢谢各位。
=====================输出如下格式的文件===================================================================
琴书】杨家将 (12 folders, 2 files, 778 bytes, 653.27 MB in total.)
│ 更多精品资源.url 117 bytes
│ 注意事项.txt 661 bytes
├─10倒反青龙阵 (0 folders, 8 files, 50.51 MB, 50.51 MB in total.)
│ 78穆桂英大破天门阵2倒反青龙阵1.mp3 5.85 MB
│ 79穆桂英大破天门阵2倒反青龙阵2.mp3 6.23 MB
│ 80穆桂英大破天门阵2倒反青龙阵3.mp3 6.94 MB
│ 81穆桂英大破天门阵2倒反青龙阵4.mp3 5.86 MB
│ 82穆桂英大破天门阵2倒反青龙阵5.mp3 6.55 MB
│ 83穆桂英大破天门阵2倒反青龙阵6.mp3 6.81 MB
│ 84穆桂英大破天门阵2倒反青龙阵7.mp3 6.33 MB
│ 85穆桂英大破天门阵2倒反青龙阵8.mp3 5.94 MB
├─11杨五郎下山 (0 folders, 8 files, 52.74 MB, 52.74 MB in total.)
│ 86穆桂英大破天门阵3杨五郎下山1.mp3 6.12 MB
│ 87穆桂英大破天门阵3杨五郎下山2.mp3 6.82 MB
│ 88穆桂英大破天门阵3杨五郎下山3.mp3 6.31 MB
│ 89穆桂英大破天门阵3杨五郎下山4.mp3 6.41 MB
│ 90穆桂英大破天门阵3杨五郎下山5.mp3 6.82 MB
│ 91穆桂英大破天门阵3杨五郎下山6.mp3 6.79 MB
│ 92穆桂英大破天门阵3杨五郎下山7.mp3 6.81 MB
│ 93穆桂英大破天门阵3杨五郎下山8.mp3 6.66 MB
├─12大破玉皇阵 (0 folders, 8 files, 49.37 MB, 49.37 MB in total.)
│ 100穆桂英大破天门阵4大破玉皇阵7.mp3 5.70 MB
│ 101穆桂英大破天门阵4大破玉皇阵8.mp3 6.07 MB
│ 94穆桂英大破天门阵4大破玉皇阵1.mp3 6.46 MB
│ 95穆桂英大破天门阵4大破玉皇阵2.mp3 6.33 MB
│ 96穆桂英大破天门阵4大破玉皇阵3.mp3 6.36 MB
作者: pcl_test 时间: 2016-11-4 18:28
本帖最后由 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
复制代码
作者: taofan712 时间: 2017-2-13 15:15
本帖最后由 taofan712 于 2017-2-13 15:40 编辑
- @echo off
- setlocal enabledelayedexpansion
- :loop
- set /p folder=拖入文件目录
- set "folder=%folder:"=%"
- cd /d "%folder%" ||goto loop
- (echo; 本文档统计于%date:~0,-3% & echo.)>tree.txt
- for /f "delims=[]" %%a in ('dir /s^|find "" /n /v^|find "所列文件总数"') do ( set /a num=%%a
- set /a wj=!num!+1 & set /a ml=!num!+2
- for /f "tokens=2 delims= " %%b in ('dir /s^|find "" /n /v^|find "[!wj!]"') do set files=%%b
- for /f "tokens=2 delims= " %%c in ('dir /s^|find "" /n /v^|find "[!ml!]"') do set folders=%%c
- echo;%cd% 【!files!个文件!folders!个目录】&echo. )>>tree.txt
- for /f "delims=" %%d in ('dir /ad /b') do ( echo; %%d
- pushd "%%~d"
- for /f "delims=" %%h in ('dir /ogn /s /b') do ( echo; %%h 【%%~zh 】 )
- popd )>>tree.txt
- for /f "delims=" %%i in ('dir /a-d /b') do ( echo; %%i 【%%~zi】 )>>tree.txt
- echo;完毕&pause>nul
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |