Pergunta

Eu estou tentando corrigir um .hta que alguém na minha empresa criou 3 ou 4 anos atrás. Agora, se você abrir um arquivo que alguém já tenha aberto, você vai perder todo o trabalho que você fez sobre ele e terá que fazê-lo manualmente mais uma vez. Então eu estava pensando apenas verificando para ver se o arquivo já está aberto e em seguida, bloqueando a edição, ou apenas fazer um pop-up dizendo "hey, se você tentar salvar você vai se decepcionar". Existe uma maneira fácil de verificar para ver se o arquivo já está aberto em javascript?

O código para abrir o arquivo é ...

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

    }
}

eo código para 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 );
}
Foi útil?

Solução

Eu vejo isso é super post antigo, mas por que não usar VBS? Se é um HTA, eles são suportados com o funcionamento em conjunto:

objFSO = CreateObject("Scripting.FileSystemObject")

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

Outras dicas

Isso é o que controle de revisão é tudo. Não é diferente do que outras formas da mesma questão que não envolve. arquivos HTA.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top