Click here to Skip to main content
15,889,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 13-Feb-18 20:39pm

1 solution

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[^]
 
Share this answer
 
Comments
sapnawat 14-Feb-18 3:02am    
Hi Maciej Los, Thanks for the reply, yes I would like to return a length of audio file. I have used strFileLength = objFile.Length but getting error -Object doesn't support this property or method: 'objFile.LENGTH' I'm new to vbs please help me to modify my code to get length of each file.
Maciej Los 14-Feb-18 3:16am    
Sorry, i don't want to be rude, but...(!!!)... Follow the link i provided in my answer. There you'll find all what you need, even a code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900