How to Get MP3 File Length by VBScript

How to Get MP3 File Length by VBScript thumbnail
Computers know a file's length, and you can determine it too

VBScript, a subset of Visual Basic, allows anyone to create useful applications that interact with Windows. If you write VBScript programs that use audio, you may need to view the properties of an MP3 file. Compressed MP3s are small, but they still take up disk space. Knowing how much space an MP3 consumes may determine how your VBS programming logic flows. Using the Windows Scripting FileSystemObject, you can create a short VBScript that tells you the file length of any MP3.

Instructions

    • 1

      Open a text editor and add the following code to a new document:

      Dim FSO
      Dim fileObject
      Dim mp3Size
      Dim fileName
      fileName = InputBox("Enter MP3 File Name ")

      The first two lines of code declare FileSystemObject and File object variables. The mp3Size variable holds the file length of an MP3, and the filename variable contains the file name of the MP3 you wish to examine. The final statement uses the InputBox function to prompt you for that file name.

    • 2

      Paste the code shown below after the code listed in the previous step:

      Set FSO = CreateObject("Scripting.FileSystemObject")
      Set fileObject = FSO.GetFile(fileName)

      mp3Size = fileObject.Size
      MsgBox "MP3 Size = " & mp3Size

      This code creates a new FileSystemObject and a new File object. The fileObject.Size function retrieves the file length of the MP3 and stores it in the mp3Size variable. The final statement displays that length in a message box.

    • 3

      Save the file and give it an extension of ".vbs." For example, if you want to call the program GetMp3Size, name the file "GetMp3Size.vbs."

    • 4

      Launch Windows Explorer and find the VBS file you saved. Double-click the file to run it, and type the name of any MP3 file in the text box that appears.

    • 5

      Press "Enter." The VBScript runs and displays the MP3's file length.

Tips & Warnings

  • This example prompts you for the name of an MP3 file. You can also set the name of an MP3 file manually instead of prompting a user for that name. To do so, assign the name of an MP3 to the fileName variable, and delete the statement that contains the InputBox function.

Related Searches:

References

Resources

  • Photo Credit Jupiterimages/Photos.com/Getty Images

Comments

Related Ads

Featured