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 回答