使用.hta要在“长度”列中获取音频文件的持续时间

时间:2018-08-10 04:07:50

标签: javascript html vbscript hta

我正在尝试创建.hta文件,以从具有.3gpp文件的文件夹中获取音频属性。 我可以成功获取文件路径,文件名,创建日期,文件类型和大小(kB)。但是我无法在“长度”列中获取音频文件的持续时间。

非常感谢您的帮助。

下面是我尝试过的代码。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>AHT Calculator For 3gpp Files</title>
<script language="vbscript">
Dim timerID
Const start_folder = "c:\Rajesh Shishodia"
Const ext = "3gpp"
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Sub window_OnLoad()
    CenterWindow 700, 600
    txtFolder.value = start_folder
    txtExtension.value = ext
    timerID = window.setInterval("RefreshTime", 1000) 'milliseconds
    RefreshTime
End Sub

Sub RefreshTime
  CurrentTime.InnerHTML = Now
End Sub

Sub cmdListFiles_onclick()
    If fso.FolderExists(txtFolder.value) Then
        Set folder = fso.GetFolder(txtFolder.value)
        For i = 1 To list.tbodies(0).rows.length
            list.tbodies(0).deleteRow 0
        Next
        ListDirectory folder, txtExtension.value
    Else
        MsgBox "No such folder"
    End If
End Sub

Sub ListDirectory(folder, ext)
    For Each file In folder.Files
        If ext = "" Or (UCase(ext) = UCase(fso.GetExtensionName(file.Name))) Then
            Set row = list.tbodies(0).insertRow(-1)
            Set cell = row.insertCell(-1)
            Set a = document.createElement("a")
            cell.appendChild a
            a.href=file.Path
            a.innerText = file.Path
            a.title = file.Path
            Set cell = row.insertCell(-1)
            cell.InnerText = file.Name
            Set cell = row.insertCell(-1)
            cell.InnerText = file.DateCreated
            Set cell = row.insertCell(-1)
            cell.InnerText = file.Type
            Set cell = row.insertCell(-1)
            cell.InnerText = Round(file.Size/1024)
            Set cell1 = row.insertCell(-1)
            cell1.InnerText = file.Length
        End If
    Next
    For Each fldr In folder.subfolders
        ListDirectory fldr, ext
    Next
End Sub

Sub cmdGetFolder_onclick()
    Set objShell = CreateObject("Shell.Application")
    Set fld = objShell.Namespace(&H11&)

    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.BrowseForFolder(0, "Select a folder:", 0,fld)

    If Not objFolder Is Nothing Then
        txtFolder.Value = objFolder.Self.Path
    End If
End Sub

Sub CenterWindow( widthX, heightY )
    self.ResizeTo widthX, heightY
    self.MoveTo (screen.Width - widthX)/2, (screen.Height - heightY)/2
End Sub
</script>
<style>
    body{
        background-color: lightgreen;
    }
    /*div for table - makes table area scroll*/
    .tbldiv{
        background-color: lightpink;
        display:block;
        width: 100%;
        height: 75%;
        overflow:scroll
    }
    table{
        border-style: collapse;
        border-width: thin;
        border-color: black;
        border-collapse:collapse;
        width: 100%;
    }
    thead{
        font-weight: bolder;
        color: darkblue;
        background-color: orange;
    }
    td{
        border-style: solid;
        border-width: thin;
    }
    tfoot{
        background-color: lightgreen;
    }
</style>
<hta:application
    applicationname="MyHTA"
    border="dialog"
    borderstyle="normal"
    caption="My HTML Application"
    contextmenu="yes"
    icon="myicon.ico"
    maximizebutton="yes"
    minimizebutton="yes"
    navigable="yes"
    scroll="yes"
    copy="yes"
    selection="yes"
    showintaskbar="yes"
    singleinstance="yes"
    sysmenu="yes"
    version="1.0"
    WINDOWSTATE="normal"
>
</head>
<body>
<span id="CurrentTime"></span>
<h1>AHT Calculation Tool For 3gpp Files</h1>
<input type="text" id="txtFolder" value="hello"/><input type="button" id="cmdGetFolder" value="..."/><br />
<input type="text" id="txtExtension" /><br />
<input type="button" id="cmdListFiles" value="List Files"/><br />
<div class="tbldiv">
    <table id="list">
        <thead>
            <tr>
                <td width="30%">File Path</td>
                <td width="20%">File Name</td>
                <td width="10%">DateCreated</td>
                <td width="10%">File Type</td>
                <td width="5%">Size(kb)</td>
                <td width="10%">Length</td>
            </tr>
        </thead>
        <tbody id="body1"></tbody>
        <tfoot><tr><td>&nbsp;</td><td>End of table</td><td><td><td><td></td></tr></tfoot>
    </table>
</div>
</body>
</object>
</html>

以下是我在运行此代码时收到的错误。

enter image description here

0 个答案:

没有答案