VBS代码获取音频文件的长度。 [英] VBS code to get length of audio file.

查看:148
本文介绍了VBS代码获取音频文件的长度。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi All,

I have a vbs code using this code i am able to get Path, Name, Size (kb), Type, Date Created, Date Last Accessed and Date Laste Modified data from a folder having audio files but i am not able to get Length of each audio files i have try-strFileSize = objFile.Length but i am getting error Object doesn't support this property or method: 'objFile.Length' please help me to correct this code.

Regrads





我尝试过:





What I have tried:

Dim objFSO, startFolder, OlderThanDate
'Flags for files
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
' Flags for browse dialog
Const BIF_returnonlyfsdirs   = &H0001
Const BIF_dontgobelowdomain  = &H0002
Const BIF_statustext         = &H0004
Const BIF_returnfsancestors  = &H0008
Const BIF_editbox            = &H0010
Const BIF_validate           = &H0020
Const BIF_browseforcomputer  = &H1000
Const BIF_browseforprinter   = &H2000
Const BIF_browseincludefiles = &H4000
currentScriptPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "") 
reportFile = currentScriptPath & "FilePropertiesReport.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDlg = WScript.CreateObject("Shell.Application")
Set objShell = CreateObject("WScript.Shell")
' Use the BrowseForFolder method.
Set objStartFolder = objDlg.BrowseForFolder (&H0, _
 "Select the folder you want to report on, su folder will also be reported", BIF_editbox + BIF_returnonlyfsdirs)
' Here we use TypeName to detect the result.
If InStr(1, TypeName(objStartFolder), "Folder") > 0 Then
	startFolder = objStartFolder.ParentFolder.ParseName(objStartFolder.Title).Path
	'Create report file and add CSV Header
	Set objReportFile = objFSO.CreateTextFile(reportfile, ForWriting)
	objReportFile.Write("Path, Name, Size (kb), Type, Date Created, Date Last Accessed, Date Laste Modified,Length"  & chr(13) & chr(10))
	'Run the function
	ReportFiles startFolder
	'Close the report
	objReportFile.Close
	'Ask to open the report now or just close
	strMbox = MsgBox("Reporting Complete. " & chr(13) & chr(10) &"The report has been saved to: " & reportFile & chr(13) & chr(10) & chr(13) & chr(10) & "Would you like to open the report now?",4,"Open report now?")
	if strMbox = 6 Then
		objShell.Run reportFile
	End if
Else
	MsgBox "An error has occured."
End if

'----------------------------------------------
' Function
'----------------------------------------------
Function ReportFiles(folderName)
   Dim objFolder, objFile, fileCollection, folderCollection, subFolder
   Set objFolder = objFSO.GetFolder(folderName)
   Set fileCollection = objFolder.Files
   For Each objFile In fileCollection
		strFilePath = chr(34) & objFile.Path & chr(34)
		strFileName = chr(34) & objFile.Name & chr(34)
		strFileSize = objFile.Size / 1024
		strFileType = chr(34) & objFile.Type & chr(34)
		strFileDateCreated = objFile.DateCreated
		strFileDateLastAccessed = objFile.DateLastAccessed
		strFileDateLastModified = objFile.DateLastModified
                strFileLength = objFile.Length
		objReportFile.Write(strFilePath & "," & strFileName & "," & strFileSize & "," & strFileType & "," & strFileDateCreated & "," & strFileDateLastAccessed & "," & strFileDateLastModified & "," & strFileLength & chr(10))
   Next
	'Loop for each sub folder
    Set folderCollection = objFolder.SubFolders
    For Each subFolder In folderCollection
       ReportFiles subFolder.Path
    Next
End Function

推荐答案

如果你想返回权重 file,使用: objFile.Size ,返回文件大小,以字节为单位。

但是如果你想返回一段音频文件,使用以下解决方案:在VBScript中读取音乐文件长度 - 堆栈溢出 [ ^ ]
If you would like to return the "weight" of file, use: objFile.Size, which returns the file size in bytes.
BUT if you would like to return a length of audio file, use solution from: Read music file length in VBScript - Stack Overflow[^]


这篇关于VBS代码获取音频文件的长度。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆