0

会社の誰かが 3 ~ 4 年前に作成した .hta を修正しようとしています。現在、他の誰かが既に開いているファイルを開くと、そのファイルに対して行った作業がすべて失われ、手動でやり直す必要があります。そのため、ファイルが既に開いているかどうかを確認してから、編集をロックするか、「保存しようとするとがっかりするだろう」というポップアップを作成することを考えていました。ファイルが既に JavaScript で開かれているかどうかを確認する簡単な方法はありますか?

ファイルを開くコードは...

function FileOpen( strSetup )
{
    if( ! strSetup )
    {
        strSetup = ShowDialog( "choose-setup", {"DialogTitle" : "Load Setup"} );
    }

    if( strSetup )
    {
        if( FileSystem.FileExists( App.Paths.Configs + "/" + strSetup + ".setup" ) )
        {
            var fFile = FileSystem.GetFile( App.Paths.Configs + "/" + strSetup + ".setup" );
            App.Config = LoadXMLDocument( fFile.Path );
            // SaveCurrentConfig();
            RefreshView( "setup-summary" );
        }
        else
        {
            alert( "Could not find setup '" + strSetup + "'" );
        }

    }
}

LoadXMLDocument のコードは...

//-----------------------------------------------------------------------------
// FUNCTION : LoadXMLDocument - Loads an XML document
// params   : strPath - the path/file of the document to load
//          : bCritical- if set true, we die if the document doesn't load
// returns  : an XML dom object on success, false otherwise
//-----------------------------------------------------------------------------

function LoadXMLDocument( strPath, bCritical )
{
    var xmlDoc = new ActiveXObject( "Msxml2.DOMDocument.3.0" );
    xmlDoc.setProperty( "SelectionLanguage", "XPath" );
    if( ! FileSystem.FileExists( strPath ) )
    {
        Error( "'" + strPath + "' is not a valid file path" );
        if( bCritical ) Abort();
        return( false );
    }
    var fFile = FileSystem.GetFile( strPath );
    xmlDoc.load( fFile.Path );
    if( xmlDoc.documentElement == null )
    {
        Error( "Could not load XML document '" + fFile.Path + "'" );
        if( bCritical ) Abort();
        return( false );
    }
    return( xmlDoc );
}
4

2 に答える 2

1

それがリビジョン管理のすべてです。関与しない同じ問題の他の形式と違いはありません。hta ファイル。

于 2009-06-17T01:34:00.890 に答える
0

これは非常に古い投稿ですが、なぜ VBS を使用しないのですか? HTA の場合は、一緒に実行することでサポートされます。

objFSO = CreateObject("Scripting.FileSystemObject")

strFilePath = "C:\test.txt"
If objFSO.FileExist(strFilePath) Then
   MsgBox "I win"
End If
于 2010-12-31T19:02:01.517 に答える