检测文件是否已在 javascript/hta 中打开

发布于 2024-07-23 21:25:05 字数 1937 浏览 3 评论 0原文

我正在尝试修复我公司某人三四年前创建的 .hta。 现在,如果您打开其他人已经打开的文件,您将丢失对其所做的所有工作,并且必须重新手动操作。 所以我想只是检查文件是否已经打开,然后锁定编辑,或者只是制作一个弹出窗口说“嘿,如果你尝试保存你会失望的”。 有没有一种简单的方法来检查文件是否已经在 J​​avaScript 中打开?

打开文件的代码是...

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 );
}

I'm trying to fix a .hta that someone at my company created 3 or 4 years ago. Right now if you open a file that someone else already has open, you'll lose any work you've done on it and will have to manually do it over again. So I was thinking just checking to see if the file is already open and then either locking editing, or just making a popup saying "hey, if you try to save you're gonna be disappointed". Is there an easy way to check to see if the file is already open in javascript?

The code to open the file is...

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 + "'" );
        }

    }
}

and the code for LoadXMLDocument is...

//-----------------------------------------------------------------------------
// 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 );
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奢华的一滴泪 2024-07-30 21:25:05

这就是修订控制的全部内容。 这与不涉及的同一问题的其他形式没有什么不同。 hta 文件。

That's what revision control is all about. It's no different than other forms of the same issue that does not involve. hta files.

第七度阳光i 2024-07-30 21:25:05

我看到这是一个非常旧的帖子,但为什么不使用 VBS 呢? 如果是 HTA,则支持它们一起运行:

objFSO = CreateObject("Scripting.FileSystemObject")

strFilePath = "C:\test.txt"
If objFSO.FileExist(strFilePath) Then
   MsgBox "I win"
End If

I see this is super old post but why not use VBS? If it's an HTA, they're supported with running together:

objFSO = CreateObject("Scripting.FileSystemObject")

strFilePath = "C:\test.txt"
If objFSO.FileExist(strFilePath) Then
   MsgBox "I win"
End If
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文