ファイルがjavascript / htaで既に開いているかどうかを検出する

StackOverflow https://stackoverflow.com/questions/1004501

  •  05-07-2019
  •  | 
  •  

質問

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 );
}
役に立ちましたか?

解決

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

objFSO = CreateObject("Scripting.FileSystemObject")

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

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top