[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] 批处理如何获取当前目录下所有子文件夹和文件的名称及大小并以树形结构输出?

本帖最后由 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

本帖最后由 taofan712 于 2017-2-13 15:40 编辑
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. :loop
  4. set /p folder=拖入文件目录
  5. set "folder=%folder:"=%"
  6. cd /d "%folder%" ||goto loop
  7. (echo; 本文档统计于%date:~0,-3% & echo.)>tree.txt
  8. for /f "delims=[]" %%a in ('dir /s^|find "" /n /v^|find "所列文件总数"') do ( set /a num=%%a
  9. set /a wj=!num!+1 & set /a ml=!num!+2
  10. for /f "tokens=2 delims= " %%b in ('dir /s^|find "" /n /v^|find "[!wj!]"') do set files=%%b
  11. for /f "tokens=2 delims= " %%c in ('dir /s^|find "" /n /v^|find "[!ml!]"') do set folders=%%c
  12. echo;%cd%  【!files!个文件!folders!个目录】&echo. )>>tree.txt
  13. for /f "delims=" %%d in ('dir /ad /b') do ( echo; %%d
  14. pushd "%%~d"
  15. for /f "delims=" %%h in ('dir /ogn /s /b') do ( echo; %%h  【%%~zh 】 )
  16. popd )>>tree.txt
  17. for /f "delims=" %%i in ('dir /a-d /b') do ( echo; %%i  【%%~zi】 )>>tree.txt
  18. echo;完毕&pause>nul
复制代码

TOP

本帖最后由 pcl_test 于 2016-11-4 22:00 编辑

vbs,修改自http://www.bathome.net/viewthread.php?tid=2914
  1. Set fso = CreateObject("Scripting.FileSystemObject")
  2. TreePath = "."  '指定文件夹/目录路径,默认为当前文件夹/目录
  3. OutFile = "OutTree.txt"
  4. If TreePath = "." Then Set TreePath = fso.GetFolder(".")
  5. fs = 0:For Each f In TreePath.Files
  6.     fs = fs+f.size
  7. Next
  8. TreeStr = TreePath.path & "  (" & TreePath.SubFolders.Count & _
  9.     " folders, "& TreePath.Files.Count &" files, "&FormatSize(fs) & _
  10.         ", "& FormatSize(TreePath.Size) & " in total.)" & vbCrLf
  11. Tree TreePath.path,""
  12. fso.CreateTextFile(OutFile, True).Write TreeStr
  13. MsgBox "查看当前目录下的OutTree.txt",vbInformation,"完成 - vbsTree"
  14. Sub Tree(Path,SFSpace)
  15.     Dim i,TempStr,FlSpace,fsize
  16.     FlSpace = SFSpace & "  "
  17.     Set CrntFolder = fso.GetFolder(Path)
  18.     i = 0:TempStr = "├─"
  19.     For Each ConFile In CrntFolder.Files
  20.         i = i + 1
  21.         If i = CrntFolder.Files.Count And CrntFolder.SubFolders.Count = 0 Then TempStr = "└─"
  22.         TreeStr = TreeStr & FlSpace & Tempstr & ConFile.name & "  (" & FormatSize(ConFile.size) & ")" & vbCrLf
  23.     Next
  24.     i = 0:TempStr = "├─"
  25.     For Each SubFolder In CrntFolder.SubFolders
  26.         fsize = 0:i = i + 1
  27.         If i = CrntFolder.SubFolders.Count Then
  28.             TempStr = "└─"
  29.             SFSpace = FlSpace & "  "
  30.         Else
  31.             SFSpace = FlSpace & "│"
  32.         End If
  33.         For Each f In SubFolder.Files
  34.             fsize = fsize+f.size
  35.         Next  
  36.         TreeStr = TreeStr & FlSpace & TempStr & SubFolder.name & "  (" & SubFolder.SubFolders.Count & _
  37.             " folders, "& SubFolder.Files.Count &" files, "& FormatSize(fsize) & _
  38.                 ", "& FormatSize(SubFolder.size) & " in total.)" & vbCrLf
  39.         Tree SubFolder,(SFSpace)
  40.     Next
  41. End Sub
  42. Function FormatSize(size)
  43.     If size >= 1099511627776 Then
  44.         FormatSize = FormatNumber(size/1099511627776, 2, true) & " TB"
  45.     ElseIf size >= 1073741824 Then
  46.         FormatSize = FormatNumber(size/1073741824, 2, true) & " GB"
  47.     ElseIf size >= 1048576 Then
  48.         FormatSize = FormatNumber(size/1048576, 2, true) & " MB"
  49.     ElseIf size >= 1024 Then
  50.         FormatSize = FormatNumber(size/1024, 2, true) & " KB"
  51.     Else
  52.         FormatSize = size & " Bytes"   
  53.     End If
  54. End Function
复制代码
1

评分人数

    • Bella: 乐于助人技术 + 1

TOP

返回列表