Glyphical

Untitled

Mar 15th, 2023
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. '-------------------------------------------------------------
  2.  
  3. 'Extract meta data details from a folder containing .ogg files
  4.  
  5. '18.2.2018 FNL
  6.  
  7. '-------------------------------------------------------------
  8.  
  9. Dim oFSO, oShell, oWshShell, oShellFolder
  10.  
  11. Dim sFolder, aCols, sTarget, oTarget, sTitle, sLine, bFirst, iCount
  12.  
  13.  
  14. Prepare
  15.  
  16. ProcessFolders(sFolder)
  17.  
  18. oTarget.Close
  19.  
  20. MsgBox iCount & " files processed." & vbLf _
  21.  
  22. & "Results are stored on the desktop in the list ""Music Files.csv""", 64, sTitle
  23.  
  24. oWshShell.Run """" & sTarget & """", 1, False
  25.  
  26.  
  27. '----------------------------------------
  28.  
  29. 'Recursively process the nominated folder
  30.  
  31. '----------------------------------------
  32.  
  33. Sub ProcessFolders(sFldr)
  34.  
  35. ProcessOneFolder(sFldr) 'extract meta data from the .ogg files in this folder
  36.  
  37. For Each oSubFolder In oFSO.GetFolder(sFldr).SubFolders
  38.  
  39. ProcessFolders(oSubFolder.Path) 'process all subfolders in this folder
  40.  
  41. Next
  42.  
  43. End Sub
  44.  
  45.  
  46. '----------------------------------------------
  47.  
  48. 'Process all .ogg files in the nominated folder
  49.  
  50. '----------------------------------------------
  51.  
  52. Sub ProcessOneFolder(sFldr)
  53.  
  54. bStart = True
  55.  
  56. Set oMusicFolder = oFSO.GetFolder(sFldr)
  57.  
  58. For Each oFile In oMusicFolder.Files
  59.  
  60. If LCase(Right(oFile.Name, 4)) = ".ogg" Then
  61.  
  62. If bStart Then oWshShell.Popup "Processing """ & sFldr & """", 2, sTitle, 64
  63.  
  64. bStart = False
  65.  
  66. iCount = iCount + 1
  67.  
  68. Set oShellFolder = oShell.Namespace(sFldr)
  69.  
  70. If bFirst Then
  71.  
  72. bFirst = False
  73.  
  74. sLine = "File name" & vbTab
  75.  
  76. For Each iCol In aCols
  77.  
  78. extract iCol, oFile.Path, True
  79.  
  80. Next
  81.  
  82. oTarget.WriteLine sLine
  83.  
  84. End If
  85.  
  86. sLine = oFile.Path & vbTab
  87.  
  88. For Each iCol In aCols
  89.  
  90. Extract iCol, oFile.Name, False
  91.  
  92. Next
  93.  
  94. oTarget.WriteLine sLine
  95.  
  96. End If
  97.  
  98. Next
  99.  
  100. End Sub
  101.  
  102.  
  103. '--------------------------------------------------------
  104.  
  105. 'Extract the meta data column data for the specified file
  106.  
  107. '--------------------------------------------------------
  108.  
  109. Sub Extract(n, sItemName, bHeader)
  110.  
  111. sItem = Trim(oShellFolder.GetDetailsOf(oShellFolder.Parsename(sItemName), n))
  112.  
  113. If n = 28 Then
  114.  
  115. If bHeader _
  116.  
  117. Then sItem = sItem & " (kBits/s)" _
  118.  
  119. Else sItem = Mid(sItem, 2, Len(sItem) -5)
  120.  
  121. End If
  122.  
  123. sLine = sLine & sItem & vbTab
  124.  
  125. End Sub
  126.  
  127.  
  128. '--------------------
  129.  
  130. 'Prepare a few things
  131.  
  132. '--------------------
  133.  
  134. Sub Prepare
  135.  
  136. Set oFSO = CreateObject("Scripting.FileSystemObject")
  137.  
  138. Set oShell = CreateObject("Shell.Application")
  139.  
  140. Set oWshShell = CreateObject("WScript.Shell")
  141.  
  142.  
  143. If wscript.Arguments.count = 0 _
  144.  
  145. Then Error "You must give the script the full name of your music folder!"
  146.  
  147. sFolder = oFSO.GetFolder(WScript.Arguments(0)).Path    'Include the full path if necessary
  148.  
  149. If Not oFSO.FolderExists(sFolder) Then Error "Cannot find the folder """ & sFolder & """."
  150.  
  151.  
  152. sTitle = "MP3 File Analyzer"
  153.  
  154. sTarget = oWshShell.SpecialFolders("Desktop") & "\Music Files.csv"
  155.  
  156. On Error Resume Next
  157.  
  158. Set oTarget = oFSO.CreateTextFile(sTarget, True, True)
  159.  
  160. iErr = Err.Number
  161.  
  162. On Error Goto 0
  163.  
  164. If iErr <> 0 Then Error "The target file """ & sTarget & """ is in use!"
  165.  
  166. aCols = Split("1 3 27 28") 'size, date, length, bit rate
  167.  
  168. bFirst = True
  169.  
  170. iCount = 0
  171.  
  172. End Sub
  173.  
  174.  
  175. '----------
  176.  
  177. 'Error exit
  178.  
  179. '----------
  180.  
  181. Sub Error(sMsg)
  182.  
  183. MsgBox sMsg, 48, sTitle
  184.  
  185. WScript.Quit
  186.  
  187. End Sub
Advertisement
Add Comment
Please, Sign In to add comment